View Source FDBC.Future (fdbc v0.1.4)

Most functions in the FoundationDB API are asynchronous, meaning that they may return to the caller before actually delivering their result. An FDBC.Future object represents a result value or error to be delivered at some future time. A future can be awaited on or periodically checked to see if it is ready. Once a Future is ready it can be resolved to get its underlying value, which is dependant on the function that created the future.

See FDBC.Transaction for examples on how futures can be used.

Summary

Functions

Awaits a future returning the result for its given type.

Awaits multiple futures returning their results.

Cancels a future and its associated asynchronous operation.

Returns true if the future is ready, where a Future is ready if it has been set to a value or an error.

Resolves a future returning the result for its given type.

Types

t()

@type t() :: %FDBC.Future{resource: term()}

t(_result)

@type t(_result) :: t()

Functions

await(future, timeout \\ 5000)

@spec await(t(), timeout()) :: any()

Awaits a future returning the result for its given type.

This is similar to resolve/1 except that a timeout can be set.

On error it raises a FDBC.Error exception.

await_many(futures, timeout \\ 5000)

@spec await_many([t()], timeout()) :: [term()]

Awaits multiple futures returning their results.

This function receives a list of futures and waits for their results in the given time interval. It returns a list of the results, in the same order as the futures supplied in the futures input argument.

A timeout, in milliseconds or :infinity, can be given with a default value of 5000. If the timeout is exceeded, then a FDBC.Error with a value of timed out is raised.

On error it raises a FDBC.Error exception.

cancel(future)

@spec cancel(t()) :: :ok

Cancels a future and its associated asynchronous operation.

If called before the future is ready, attempts to resolve/1 the future will result in a FDBC.Error exception with operation_cancelled error.

Cancelling a future which is already ready has no effect.

Note

Even if a future is not ready, its associated asynchronous operation may have succesfully completed and be unable to be cancelled.

ready?(future)

@spec ready?(t()) :: boolean()

Returns true if the future is ready, where a Future is ready if it has been set to a value or an error.

resolve(future)

@spec resolve(t()) :: any()

Resolves a future returning the result for its given type.

On error it raises a FDBC.Error exception.