Skip to main content

AsyncFuture

No overview available.

Methods


set()

@classmethod
def set(
val: interface{},
err: error
)

Sets the result of the future with a value or an error. This method marks the future as ready and unblocks any callers waiting on get() or Get().

Parameters

NameTypeDescription
valinterface{}The value to be stored in the future upon completion.
errerrorAn error to be stored in the future if the operation failed.

get()

@classmethod
def get() - > (interface{}, error)

Retrieves the value and error from the future. This method blocks until the future is ready (i.e., set() has been called).

Returns

TypeDescription
(interface{}, error)The value and error stored in the future. The value will be nil if an error occurred, and the error will be nil if the operation was successful.

Ready()

@classmethod
def Ready() - > bool

Checks if the future has completed and its result is available. Callers can use this to poll the future's status without blocking.

Returns

TypeDescription
boolTrue if the future has completed (either successfully or with an error), false otherwise.

Get()

@classmethod
def Get(
ctx: context.Context
) - > (interface{}, error)

Retrieves the value and error from the future, respecting a provided context for cancellation or timeouts. This method blocks until the future is ready or the context is cancelled/times out.

Parameters

NameTypeDescription
ctxcontext.ContextThe context to use for cancellation and timeout. If the context is cancelled, this method will return early with the context's error.

Returns

TypeDescription
(interface{}, error)The value and error stored in the future. If the context is cancelled or times out before the future is ready, the context's error will be returned.