From 9ce2cff5c0906a0a2c1cd96d2fb2cdbf237eee2a Mon Sep 17 00:00:00 2001 From: Eric Lippmann Date: Sun, 8 Aug 2021 22:21:45 +0200 Subject: [PATCH] Introduce WaiterFunc type The WaiterFunc type is an adapter to allow the use of ordinary functions as Waiter. --- pkg/contracts/contracts.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/pkg/contracts/contracts.go b/pkg/contracts/contracts.go index 25513aa7..51594144 100644 --- a/pkg/contracts/contracts.go +++ b/pkg/contracts/contracts.go @@ -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 {