Documentation
¶
Index ¶
- func Async[T any](f func() T) <-chan T
- func AsyncContext[T any](ctx context.Context, f func() T) <-chan T
- func AsyncContextOrErr[T any](ctx context.Context, f func(context.Context) (T, error)) (<-chan T, <-chan error)
- func AsyncOrErr[T any](f func() (T, error)) (<-chan T, <-chan error)
- func Wait[T any](v <-chan T) T
- func WaitContext[T any](ctx context.Context, v <-chan T) (T, error)
- func WaitContextOrErr[T any](ctx context.Context, v <-chan T, err <-chan error) (T, error)
- func WaitOrErr[T any](v <-chan T, err <-chan error) (T, error)
- type Promise
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Async ¶
func Async[T any](f func() T) <-chan T
Async runs the provided function in a separate goroutine and returns a channel that will receive the result of the function. The function fn will be executed asynchronously and its result will be sent to the channel. The channel will be closed after the result is sent.
func AsyncContext ¶ added in v0.2.6
AsyncContext runs the provided function in a separate goroutine and returns a channel that will receive the result of the function. The function fn will be executed asynchronously and its result will be sent to the channel. The channel will be closed after the result is sent. If the context is done, the function will not be executed. The function will not be executed if the context is done.
func AsyncContextOrErr ¶ added in v0.2.6
func AsyncContextOrErr[T any](ctx context.Context, f func(context.Context) (T, error)) (<-chan T, <-chan error)
AsyncContextOrErr runs the provided function in a separate goroutine and returns two channels:
one that will receive the result of the function, and another that will receive any error that occurs during the function execution.
The function fn will be executed asynchronously and its result and error will be sent to the respective channels. The channels will be closed after the result or error is sent. If the provided function is nil, an error will be sent to the error channel. If the context is done, the function will not be executed. The function will not be executed if the context is done.
func AsyncOrErr ¶
AsyncOrErr runs the provided function in a separate goroutine and returns two channels: one that will receive the result of the function, and another that will receive any error that occurs during the function execution. The function fn will be executed asynchronously and its result and error will be sent to the respective channels. The channels will be closed after the result or error is sent. If the provided function is nil, an error will be sent to the error channel.
func Wait ¶
func Wait[T any](v <-chan T) T
Wait waits for a value to be available on the provided channel.
The channel v must be a receive-only channel of type T. The function blocks until a value is received from the channel, and then returns that value.
Parameters:
- v: A receive-only channel of type T.
Returns:
- T: The value received from the channel.
func WaitContext ¶ added in v0.2.6
WaitContext waits for a value to be available on the provided channel within the given context.
The channel v must be a receive-only channel of type T. The function blocks until a value is received from the channel or the context is done.
Parameters:
- ctx: The context to control the waiting process.
- v: A receive-only channel of type T.
Returns:
- T: The value received from the channel if successful.
- error: The error that caused the waiting process to be done.
func WaitContextOrErr ¶ added in v0.2.6
WaitContextOrErr waits for a value to be available on the provided channel within the given context. If a value is received from the channel, it is returned along with a nil error. If an error is received from the error channel, it is returned along with the received error. If the context is done, the function returns the last received value and an error indicating the context is done.
Parameters:
- ctx: The context to control the waiting process.
- v: A receive-only channel of type T.
- err: A receive-only channel of type error.
Returns:
- T: The value received from the channel if successful.
- error: The error that caused the waiting process to be done.
func WaitOrErr ¶
WaitOrErr waits for a value to be available on the provided channel or an error to be available on the provided error channel.
The channel v must be a receive-only channel of type T. The function blocks until a value is received from the channel or an error is received from the error channel, and then returns the value or the error received from the channel.
Parameters:
- v: A receive-only channel of type T.
- err: A receive-only channel of type error.
Returns:
- T: The value received from the channel if successful.
- error: The error received from the error channel if successful.