A11 (C++ runtime)
Native C++ implementation of the A11 action and streaming runtime
Loading...
Searching...
No Matches
a11::Future< T > Class Template Reference

Shared handle to one asynchronous result. More...

#include <cpp/a11/concurrency/future.h>

Public Member Functions

 Future ()=default
 
bool valid () const
 Whether this handle refers to shared completion state.
 
bool IsReady () const
 Whether the producer has published either a value or an error.
 
absl::Status Cancel () const
 Request cancellation from the operation producing this result.
 
absl::StatusOr< TAwait (absl::Time deadline=absl::InfiniteFuture()) const
 Wait for and return the result up to an absolute deadline.
 
void OnReady (absl::AnyInvocable< void(const absl::StatusOr< T > &)> callback) const
 Run callback once when the result becomes available.
 

Friends

class Promise< T >
 
template<typename U >
Future< USubmit (absl::AnyInvocable< absl::StatusOr< U >() && > work, thread::TreeOptions tree_options)
 
template<typename U >
Future< U > SubmitWithCancellationHook (absl::AnyInvocable< absl::StatusOr< U >() && > work, std::function< void()> cancellation_hook, thread::TreeOptions tree_options)
 

Detailed Description

template<typename T>
class a11::Future< T >

Shared handle to one asynchronous result.

Futures are cheap to copy and may have several waiters. Await() integrates with A11 fibers when called inside the runtime and parks an ordinary thread otherwise. OnReady() is the callback-oriented path used by high-cardinality pumps and language bindings.

Cancellation is a request to the producing operation; callers must still observe the future to learn its eventual result.

Constructor & Destructor Documentation

◆ Future()

template<typename T >
a11::Future< T >::Future ( )
default

Member Function Documentation

◆ Await()

template<typename T >
absl::StatusOr< T > a11::Future< T >::Await ( absl::Time  deadline = absl::InfiniteFuture< T >()) const
inline

Wait for and return the result up to an absolute deadline.

A timeout or cancellation of the waiting fiber does not itself overwrite the producer's result; another observer may continue waiting.

◆ Cancel()

template<typename T >
absl::Status a11::Future< T >::Cancel ( ) const
inline

Request cancellation from the operation producing this result.

Returns
OK when the request was delivered, or Unimplemented when the producer did not install a cancellation source.

◆ IsReady()

template<typename T >
bool a11::Future< T >::IsReady ( ) const
inline

Whether the producer has published either a value or an error.

◆ OnReady()

template<typename T >
void a11::Future< T >::OnReady ( absl::AnyInvocable< void(const absl::StatusOr< T > &)>  callback) const
inline

Run callback once when the result becomes available.

The callback runs immediately when the future is already ready. It must not retain the referenced StatusOr beyond the callback invocation.

◆ valid()

template<typename T >
bool a11::Future< T >::valid ( ) const
inline

Whether this handle refers to shared completion state.

Friends And Related Symbol Documentation

◆ Promise< T >

template<typename T >
friend class Promise< T >
friend

◆ Submit

template<typename T >
template<typename U >
Future< U > Submit ( absl::AnyInvocable< absl::StatusOr< U >() && >  work,
thread::TreeOptions  tree_options 
)
friend

◆ SubmitWithCancellationHook

template<typename T >
template<typename U >
Future< U > SubmitWithCancellationHook ( absl::AnyInvocable< absl::StatusOr< U >() && >  work,
std::function< void()>  cancellation_hook,
thread::TreeOptions  tree_options 
)
friend

The documentation for this class was generated from the following file: