Promise Package Types
Promise
type Promise[T any] interface {
Resolve(result T)
Reject(err error)
Then(func(T) interface{}) Promise[interface{}]
Catch(func(error) interface{}) Promise[interface{}]
Await() (T, error)
AwaitWithContext(ctx context.Context) (T, error)
AwaitWithTimeout(timeout time.Duration) (T, error) // Added method
Cancel()
}
Promise represents an asynchronous operation that can be resolved or rejected.
promiseImpl
type promiseImpl[T any] struct {
ctx context.Context
cancelFunc context.CancelFunc
result T
err error
doneChan chan struct{}
once sync.Once
}
promiseImpl is a concrete type implementing the Promise interface.
Last modified: 28 January 2025