FdbFuture

Namespace: FoundationDB.Client.Native · class

Helper class to create FDBFutures

Methods

Create

static FdbFuture<T> Create<T>(CancellationToken ct, TaskCreationOptions options = 0)

Create a generic FdbFuture that has a lifetime tied to a cancellation token

  • ct — Token used to cancel the future from the outside
  • options — Optional creation options for the underlying Task

Returns: Future that will automatically be cancelled if the linked token is cancelled.

This is mostly used to create Watches or futures that behave similarly to watches.

CreateTaskFromHandle

static Task CreateTaskFromHandle(FutureHandle handle, CancellationToken ct)

Wraps a FDBFuture* pointer into a Task

  • handle — FDBFuture* pointer
  • ct — Optional cancellation token that can be used to cancel the future

Returns: Object that tracks the execution of the FDBFuture handle

static Task<TResult> CreateTaskFromHandle<TState, TResult>(FutureHandle handle, TState state, Func<FutureHandle, TState, TResult> selector, CancellationToken ct)

Wraps a FDBFuture* pointer into a Task

  • handle — FDBFuture* pointer
  • state — State that is passed to the result selector
  • selector — Lambda that will be called once the future completes successfully, to extract the result from the future handle.
  • ct — Optional cancellation token that can be used to cancel the future

Returns: Task that will either return the result of the continuation lambda, or an exception

CreateTaskFromHandleArray

static Task<TResult> CreateTaskFromHandleArray<TState, TResult>(FutureHandle[] handles, TState state, Action<FutureHandle, int, TState> completionHandler, Func<TState, TResult> resultSelector, CancellationToken ct)

Wraps multiple FdbFuture handles into a single Task that returns an array of T

  • handles — Array of FDBFuture* pointers
  • state — State that is passed to the result selector
  • completionHandler — Lambda that will be called once for each future that completes successfully, to extract the decoded value for this future handle.
  • resultSelector — Lambda that will be called after all the results have been decoded, to extract the final result of the operation
  • ct — Optional cancellation token that can be used to cancel the future

Returns: Task that will either return the result of the operation, or an exception

If at least one future fails, the whole task will fail.

CreateValueTaskFromHandle

static ValueTask<TResult> CreateValueTaskFromHandle<TState, TResult>(FutureHandle handle, TState state, Func<FutureHandle, TState, TResult> selector, CancellationToken ct)

Wraps a FDBFuture* pointer into a ValueTask that MUST be consumed exactly once

  • handle — FDBFuture* pointer
  • state — State that is passed to the result selector
  • selector — Lambda that will be called once the future completes successfully, to extract the result from the future handle.
  • ct — Optional cancellation token that can be used to cancel the future

On the netstandard2.0 target this wraps the underlying Task (same allocations as before); on modern targets no Task is allocated at all.

CreateValueTaskFromHandleArray

static ValueTask<TResult> CreateValueTaskFromHandleArray<TState, TResult>(FutureHandle[] handles, TState state, Action<FutureHandle, int, TState> completionHandler, Func<TState, TResult> resultSelector, CancellationToken ct)

Wraps multiple FDBFuture* pointers into a single ValueTask that MUST be consumed exactly once

If at least one future fails, the whole task will fail. On the netstandard2.0 target this wraps the underlying Task.

FromHandle

static FdbFutureSingle<TState, TResult> FromHandle<TState, TResult>(FutureHandle handle, TState state, Func<FutureHandle, TState, TResult> selector, CancellationToken ct)

Creates a new FdbFutureSingle from an FDBFuture* pointer

  • handle — FDBFuture* pointer
  • state — State that is passed to the result selector
  • selector — Func that will be called to get the result once the future completes (and did not fail)
  • ct — Optional cancellation token that can be used to cancel the future

Returns: Object that tracks the execution of the FDBFuture handle