Introduce WaiterFunc type

The WaiterFunc type is an adapter to allow the use of ordinary
functions as Waiter.
This commit is contained in:
Eric Lippmann 2021-08-08 22:21:45 +02:00
parent 585d1e6bb5
commit 9ce2cff5c0

View file

@ -66,6 +66,15 @@ type Waiter interface {
Wait() error // Wait waits for execution to complete.
}
// The WaiterFunc type is an adapter to allow the use of ordinary functions as Waiter.
// If f is a function with the appropriate signature, WaiterFunc(f) is a Waiter that calls f.
type WaiterFunc func() error
// Wait implements the Waiter interface.
func (f WaiterFunc) Wait() error {
return f()
}
// Initer implements the Init method,
// which initializes the object in addition to zeroing.
type Initer interface {