thrift.util.future

interface TFuture(ResultType)
Represents an operation which is executed asynchronously and the result of which will become available at some point in the future.
Once a operation is completed, the result of the operation can be fetched via the get() family of methods. There are three possible cases: Either the operation succeeded, then its return value is returned, or it failed by throwing, in which case the exception is rethrown, or it was cancelled before, then a TCancelledException is thrown. There might be TFuture implementations which never possibly enter the cancelled state.

All methods are thread-safe, but keep in mind that any exception object or result (if it is a reference type, of course) is shared between all get()-family invocations.
TFutureStatus status() [@property]
The status the operation is currently in.
An operation starts out in RUNNING status, and changes state to one of the others at most once afterwards.
TAwaitable completion() [@property]
A TAwaitable triggered when the operation leaves the RUNNING status.
ResultType waitGet() [final]
Convenience shorthand for waiting until the result is available and then get()ing it.
If the operation has already completed, the result is immediately returned.

The result of this method is »alias this«'d to the interface, so that TFuture can be used as a drop-in replacement for a simple value in synchronous code.
ResultType waitGet(Duration timeout) [final]
Convenience shorthand for waiting until the result is available and then get()ing it.
If the operation completes in time, returns its result (resp. throws an exception for the failed/cancelled cases). If not, throws a TFutureException.
ResultType get()
Returns the result of the operation.

Throws:

TFutureException if the operation has been cancelled, TCancelledException if it is not yet done; the set exception if it failed.
Exception getException()
Returns the captured exception if the operation failed, or null otherwise.

Throws:

TFutureException if not yet done, TCancelledException if the operation has been cancelled.
enum TFutureStatus : byte
The states the operation offering a future interface can be in.
RUNNING
The operation is still running.
SUCCEEDED
The operation completed without throwing an exception.
FAILED
The operation completed by throwing an exception.
CANCELLED
The operation was cancelled.
class TPromise(ResultType) : TFuture!ResultType
A TFuture covering the simple but common case where the result is simply set by a call to succeed()/fail().
All methods are thread-safe, but usually, succeed()/fail() are only called from a single thread (different from the thread(s) waiting for the result using the TFuture interface, though).
void succeed(ResultType result)
Sets the result of the operation, marks it as done, and notifies any waiters.
If the operation has been cancelled before, nothing happens.

Throws:

TFutureException if the operation is already completed.
void fail(Exception exception)
Marks the operation as failed with the specified exception and notifies any waiters.
If the operation was already cancelled, nothing happens.

Throws:

TFutureException if the operation is already completed.
void complete(TFuture!ResultType future)
Marks this operation as completed and takes over the outcome of another TFuture of the same type.
If this operation was already cancelled, nothing happens. If the other operation was cancelled, this operation is marked as failed with a TCancelledException.

Throws:

TFutureException if the passed in future was not completed or this operation is already completed.
void cancel()
Marks this operation as cancelled and notifies any waiters.
If the operation is already completed, nothing happens.
class TFutureException : TException
this(string msg = "", string file = __FILE__, size_t line = __LINE__, Throwable next = null)
template TFutureInterface(Interface)
Creates an interface that is similiar to a given one, but accepts an additional, optional TCancellation parameter each method, and returns TFutures instead of plain return values.
For example, given the following declarations:
1
2
3
4
5
interface Foo {
  void bar();
  string baz(int a);
}
alias TFutureInterface!Foo FutureFoo;

FutureFoo would be equivalent to:
1
2
3
4
interface FutureFoo {
  TFuture!void bar(TCancellation cancellation = null);
  TFuture!string baz(int a, TCancellation cancellation = null);
}
class TFutureAggregatorRange(T) [final]
An input range that aggregates results from multiple asynchronous operations, returning them in the order they arrive.
Additionally, a timeout can be set after which results from not yet finished futures will no longer be waited for, e.g. to ensure the time it takes to iterate over a set of results is limited.
this(TFuture!T[] futures, TCancellationOrigin childCancellation, Duration timeout = dur!"hnsecs"(0))
Constructs a new instance.

Parameters:

futuresThe set of futures to collect results from.
timeoutIf positive, not yet finished futures will be cancelled and their results will not be taken into account.
bool empty() [@property]
Whether the range is empty.
This is the case if the results from the completed futures not having failed have already been popped and either all future have been finished or the timeout has expired.

Potentially blocks until a new result is available or the timeout has expired.
T front()
Returns the first element from the range.
Potentially blocks until a new result is available or the timeout has expired.

Throws:

TException if the range is empty.
void popFront()
Removes the first element from the range.
Potentially blocks until a new result is available or the timeout has expired.

Throws:

TException if the range is empty.
size_t completedCount() [@property, const]
The number of futures the result of which has been returned or which have failed so far.
Exception[] exceptions() [@property]
The exceptions collected from failed TFutures so far.
TFutureAggregatorRange!T tFutureAggregatorRange(T)(TFuture!T[] futures, TCancellationOrigin childCancellation, Duration timeout = dur!"hnsecs"(0))
TFutureAggregatorRange construction helper to avoid having to explicitly specify the value type, i.e. to allow the constructor being called using IFTI (see D Bugzilla enhancement requet 6082).