Documentation
¶
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Until ¶
func Until[T any]( ctx context.Context, log *slog.Logger, check func(context.Context) (T, error), ) (T, error)
Example (ContextCanceled) ¶
ctx, cancel := context.WithCancel(context.Background())
cancel()
_, err := Until(ctx, nil, func(context.Context) (string, error) {
return "", errors.New("not ready")
})
fmt.Println(err == context.Canceled)
Output: true
Example (Success) ¶
value, err := Until(context.Background(), nil, func(ctx context.Context) (string, error) {
return "ready", nil
})
fmt.Println(value, err == nil)
Output: ready true
func UntilWithOptions ¶
func UntilWithOptions[T any]( ctx context.Context, check func(context.Context) (T, error), opts Options, ) (T, error)
Example ¶
value, err := UntilWithOptions(
context.Background(),
func(ctx context.Context) (int, error) {
return 42, nil
},
Options{
InitialBackoff: 100 * time.Millisecond,
MaxBackoff: time.Second,
},
)
fmt.Println(value, err == nil)
Output: 42 true
Types ¶
Click to show internal directories.
Click to hide internal directories.