Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Chan ¶ added in v0.37.0
type Chan[T any] struct { // contains filtered or unexported fields }
Chan represents a future that will complete with a single value of type T. This struct is non-blocking and allows for parallel callbacks to be registered. The result of the future can be accessed via the Get() method or by receiving from the channel returned by the Receive() method. The future can be completed with a value of type T using the Complete() method. The future can be chained with other futures using the ThenAccept() and ThenApply() methods. The future is thread-safe and can be used concurrently. The ThenAccept(), Get() and Receive() methods can be called multiple times to receive the same result. Multiple calls to the Complete() method will only complete the future once.
func NewChan ¶ added in v0.37.0
NewChan returns a new Chan that will complete with a single value of type T.
func ThenApply ¶ added in v0.37.0
ThenApply returns a new future that will complete with the result of the callback applied to the result of this future. This method is non-blocking and returns immediately.
func (*Chan[T]) Complete ¶ added in v0.37.0
Complete sets the result of this future once and propagates it to all current and future listeners. Multiple calls to this method will not have any effect. This method is non-blocking and returns immediately.
func (*Chan[T]) Get ¶ added in v0.37.0
func (f *Chan[T]) Get() T
Get returns the result of this future or blocks indefinitely until the result is available. Multiple calls to this method will all block until the result is available.
func (*Chan[T]) Receive ¶ added in v0.37.0
func (f *Chan[T]) Receive() <-chan T
Receive returns a channel that will receive the result of this future. The channel will be closed once after the result was sent. Multiple calls to this method will return new channels that will receive the same result.
func (*Chan[T]) ThenAccept ¶ added in v0.37.0
ThenAccept registers a parallel callback to be called when the future is completed. This method is non-blocking and returns immediately.
type Future ¶
type Future[T any] struct { // contains filtered or unexported fields }
Future is a struct that holds a value of type T, a slice of callbacks to be called when the value is set, a boolean to track if the callbacks have been called, and a mutex for thread safety.
func ThenCompose ¶ added in v0.39.0
ThenCompose registers a callback to be called when the Future is completed and returns a new Future.
func (*Future[T]) Complete ¶
Complete sets the value and calls the registered callbacks if they haven't been called yet.
func (*Future[T]) ThenAccept ¶
ThenAccept registers a callback to be called when the Future is completed.