libqi-api
2.8.7.4
|
#include <strand.hpp>
Public Types | |
using | OptionalErrorMessage = boost::optional< std::string > |
Public Member Functions | |
Strand () | |
Construct a strand that will schedule work on the default event loop. More... | |
Strand (qi::ExecutionContext &executionContext) | |
Construct a strand that will schedule work on executionContext. More... | |
~Strand () | |
Call detroy() More... | |
void | join () QI_NOEXCEPT(true) |
OptionalErrorMessage | join (std::nothrow_t) QI_NOEXCEPT(true) |
qi::Future< void > | async (const boost::function< void()> &cb, qi::SteadyClockTimePoint tp) override |
qi::Future< void > | async (const boost::function< void()> &cb, qi::Duration delay) override |
bool | isInThisContext () const override |
template<typename F > | |
auto | schedulerFor (F &&func, boost::function< void()> onFail={}, ExecutionOptions options=defaultExecutionOptions()) -> detail::Stranded< typename std::decay< F >::type > |
template<typename F > | |
auto | unwrappedSchedulerFor (F &&func, boost::function< void()> onFail={}, ExecutionOptions options=defaultExecutionOptions()) -> detail::StrandedUnwrapped< typename std::decay< F >::type > |
Future< void > | defer (const boost::function< void()> &cb, MicroSeconds delay=MicroSeconds::zero(), ExecutionOptions options=defaultExecutionOptions()) |
![]() | |
virtual | ~ExecutionContext () |
template<typename R > | |
boost::disable_if < std::is_same< R, void > , qi::Future< R > >::type | async (const boost::function< R()> &callback, qi::Duration delay) |
template<typename R > | |
boost::disable_if < std::is_same< R, void > , qi::Future< R > >::type | async (const boost::function< R()> &callback, qi::SteadyClockTimePoint tp) |
template<typename R > | |
qi::Future< R > | async (const detail::Function< R()> &callback) |
template<typename F > | |
void | post (F &&callback, ExecutionOptions options=defaultExecutionOptions()) |
post a callback to be executed as soon as possible More... | |
template<typename F , typename R = ka::Decay<decltype(std::declval<F>()())>> | |
qi::Future< R > | asyncAt (F &&callback, qi::SteadyClockTimePoint tp, ExecutionOptions options=defaultExecutionOptions()) |
call a callback asynchronously to be executed on tp More... | |
template<typename F , typename R = ka::Decay<decltype(std::declval<F>()())>> | |
qi::Future< R > | asyncDelay (F &&callback, qi::Duration delay, ExecutionOptions options=defaultExecutionOptions()) |
call a callback asynchronously to be executed in delay More... | |
template<typename F > | |
auto | async (F &&callback, ExecutionOptions options=defaultExecutionOptions()) -> decltype(asyncDelay(std::forward< F >(callback), qi::Duration(0), options)) |
template<typename F , typename R > | |
Future< R > | asyncAt (F &&callback, qi::SteadyClockTimePoint tp, ExecutionOptions options) |
template<typename F , typename R > | |
Future< R > | asyncDelay (F &&callback, qi::Duration delay, ExecutionOptions options) |
Additional Inherited Members |
Class that schedules tasks sequentially
A strand allows one to schedule work on an eventloop with the guaranty that two callback will never be called concurrently.
Methods are thread-safe except for destructor which must never be called concurrently.
Definition at line 125 of file strand.hpp.
using qi::Strand::OptionalErrorMessage = boost::optional<std::string> |
Definition at line 128 of file strand.hpp.
qi::Strand::Strand | ( | ) |
Construct a strand that will schedule work on the default event loop.
qi::Strand::Strand | ( | qi::ExecutionContext & | executionContext | ) |
Construct a strand that will schedule work on executionContext.
qi::Strand::~Strand | ( | ) |
Call detroy()
|
overridevirtual |
call a callback asynchronously to be executed on tp
Implements qi::ExecutionContext.
|
overridevirtual |
call a callback asynchronously to be executed in delay
Implements qi::ExecutionContext.
Future<void> qi::Strand::defer | ( | const boost::function< void()> & | cb, |
MicroSeconds | delay = MicroSeconds::zero() , |
||
ExecutionOptions | options = defaultExecutionOptions() |
||
) |
Defers a function for execution in the strand thus without allowing the strand to call it from inside this function. It implies that this function always returns immediately.
cb | The function to execute. |
delay | Duration that defer will wait (without blocking the caller) before queuing the function for execution. If zero (the default value), the function will be queued immediately. |
options | Execution options. |
|
overridevirtual |
Implements qi::ExecutionContext.
void qi::Strand::join | ( | ) |
Joins the strand.
This will wait for currently running tasks to finish and will drop all tasks scheduled from the moment of the call on. A strand can't be reused after it has been join()ed.
It is safe to call this method concurrently with other methods. All the returned futures will be set to error. : Under extreme circumstances such as system memory exhaustion, this method could still throw a std::bad_alloc
exception, thus causing a call to std::terminate
because of the noexcept
specifier. This behavior is considered acceptable.
OptionalErrorMessage qi::Strand::join | ( | std::nothrow_t | ) |
Joins the strand.
This version catches any exception and returns its message. This version must be preferred in destructors to prevent abort.
If there is no exception, an empty error message is returned.
Example: Preventing a destructor to throw exceptions because of join
.
|
inline |
Definition at line 235 of file strand.hpp.
|
inline |
Returns a function which, when called, defers a call to the original function to the strand, but with the return value unwrapped if possible.
Definition at line 248 of file strand.hpp.