Returns a Task that, when started, starts a timer of duration 'timeoutDuration' and awaits the passed SemiAwaitable.
Declared in <folly/coro/Timeout.h>
template<
typename SemiAwaitable,
typename Duration,
typename TimekeeperPtr = std::nullptr_t>
/* implementation-defined */
timeout(
SemiAwaitable semiAwaitable,
Duration timeoutDuration,
TimekeeperPtr tk = nullptr);
If the timeoutDuration elapses before the 'co_await semiAwaitable' operation completes then requests cancellation of the child operation and completes with an error of type folly::FutureTimeout. Otherwise, if the 'co_await semiAwaitable' operation completes before the timeoutDuration elapses then cancels the timer and completes with the result of the semiAwaitable.
IMPORTANT: The operation passed as the first argument must be able to respond to a request for cancellation on the CancellationToken injected to it via folly::coro::co_withCancellation in a timely manner for the timeout to work as expected.
If a timekeeper is provided then uses that timekeeper to start the timer, otherwise uses the process' default TimeKeeper if 'tk' is null.
Throws folly::FutureTimeout if the timeout fires. refcode folly/docs/examples/folly/coro/DetachOnCancel.cpp
A task completing with the operation's result, or an error on timeout.
| Name | Description |
|---|---|
| semiAwaitable | The operation to await under the timeout. |
| timeoutDuration | The duration after which the timer fires. |
| tk | The timekeeper used to start the timer, or null for the default. |