promise

package
v1.0.0-beta.9 Latest Latest
Warning

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

Go to latest
Published: Jun 7, 2024 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Promise

type Promise[T any] struct {
	// contains filtered or unexported fields
}

Promise is a promise that can be resolved or rejected.

func New

func New[T any](optResolver ...func(p *Promise[T])) *Promise[T]

New creates a new promise.

func (*Promise[T]) Err

func (p *Promise[T]) Err() error

Err returns the error of the promise (or nil if the promise was not rejected).

func (*Promise[T]) IsEmpty

func (p *Promise[T]) IsEmpty() bool

IsEmpty returns true if the promise has no updateCallbacks.

func (*Promise[T]) OnComplete

func (p *Promise[T]) OnComplete(callback func()) func()

OnComplete registers a callback that is called when the promise is resolved or rejected.

func (*Promise[T]) OnError

func (p *Promise[T]) OnError(callback func(err error)) func()

OnError registers a callback that is called when the promise is rejected.

func (*Promise[T]) OnSuccess

func (p *Promise[T]) OnSuccess(callback func(result T)) (cancel func())

OnSuccess registers a callback that is called when the promise is resolved.

func (*Promise[T]) Reject

func (p *Promise[T]) Reject(err error) *Promise[T]

Reject rejects the promise with the given error.

func (*Promise[T]) Resolve

func (p *Promise[T]) Resolve(result T) *Promise[T]

Resolve resolves the promise with the given result.

func (*Promise[T]) ResolveDynamically

func (p *Promise[T]) ResolveDynamically(resolve func() T) *Promise[T]

ResolveDynamically resolves the promise with the result of the given resolve function.

func (*Promise[T]) Result

func (p *Promise[T]) Result() T

Result returns the result of the promise (or the zero value if the promise was not resolved).

func (*Promise[T]) WaitComplete

func (p *Promise[T]) WaitComplete()

func (*Promise[T]) WasCompleted

func (p *Promise[T]) WasCompleted() bool

WasCompleted returns true if the promise was resolved or rejected.

func (*Promise[T]) WasRejected

func (p *Promise[T]) WasRejected() bool

WasRejected returns true if the promise was rejected.

func (*Promise[T]) WasResolved

func (p *Promise[T]) WasResolved() bool

WasResolved returns true if the promise was resolved.

Jump to

Keyboard shortcuts

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