wait

package
v1.29.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 8, 2026 License: Apache-2.0 Imports: 4 Imported by: 0

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

type Options

type Options struct {
	Logger         *slog.Logger
	InitialBackoff time.Duration
	MaxBackoff     time.Duration
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL