The write side of a promise/future contract used to fulfill a Future.

Synopsis

Declared in <folly/coro/Promise.h>

template<typename T>
class Promise;

Member Functions

Name

Description

Promise [constructor]

Constructors

~Promise [destructor]

Destroys the promise, breaking it if it was never fulfilled.

operator=

Assignment operators

getCancellationToken

Returns the cancellation token associated with this promise.

isFulfilled

Returns whether the promise has already been fulfilled.

setException

Fulfills the promise with an exception.

setResult

Fulfills the promise with a Try holding a value or exception.

setValue

Fulfills the promise with a value.

trySetException

Fulfills the promise with an exception if not already fulfilled.

trySetExceptionWith

Fulfills the promise with an exception returned from calling func if not already fulfilled.

trySetResult

Fulfills the promise with a Try if not already fulfilled.

trySetValue

Fulfills the promise with a value if not already fulfilled.

trySetWith

Fulfills the promise with a value/Try returned from calling func if not already fulfilled.

valid

Returns whether the promise refers to a valid shared state.

Friends

Non-Member Functions

Name

Description

makePromiseContract

makePromiseContract can help you migrating your non‐coroutine code base to coroutine. If your code already uses Future/SemiFuture, you don't need this tool. A common use case is with async callback functions. In the example, we can pass a callback function into the legacy code sleepAndNotify and sleepAndNotify sets the promise on completion. Consider to use detachOnCancel with this makePromiseContract to handle long running (longer than your timeout) tasks that don't handle cancellation properly.

Created with MrDocs