- Aldebaran documentation |
- C++ Libraries |
- index

libqi-api 2.8.7.4

- Main Page
- Related Pages
- Namespaces
- Classes
- Files
- Examples

- Class List
- Class Hierarchy
- Class Members

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Classes | Public Types | Public Member Functions | List of all members
qi::Strand Class Reference

`#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())
Public Member Functions inherited from qi::ExecutionContext
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

## Detailed Description

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.

## Member Typedef Documentation

using qi::Strand::OptionalErrorMessage = boost::optional<std::string>

Definition at line 128 of file strand.hpp.

## Constructor & Destructor Documentation

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()

## Member Function Documentation

qi::Future<void> qi::Strand::async | ( | const boost::function< void()> & | callback,
|  | qi::SteadyClockTimePoint | tp
| ) |  |
| override virtual

call a callback asynchronously to be executed on tp

Deprecated:
  since 2.5

Implements qi::ExecutionContext.

qi::Future<void> qi::Strand::async | ( | const boost::function< void()> & | callback,
|  | qi::Duration | delay
| ) |  |
| override virtual

call a callback asynchronously to be executed in delay

Deprecated:
  since 2.5

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.

Parameters

  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.

Returns
  A future that is set once the function argument is executed

bool qi::Strand::isInThisContext | ( |  | ) | const
| override virtual

Returns
  true if current code is running in this strand, false otherwise. If the strand is dying (destroy() has been called, returns false)

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.

Deprecated:
  Use join() which is currently noexcept.

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`.

~MyActor() {
if (const auto error = _strand.join(std::nothrow)) {
qiLogWarning() << "Error while joining the strand. Detail: " << *error;
}
}
template<typename F >

auto qi::Strand::schedulerFor | ( | F && | func,
|  | boost::function< void()> | onFail = `{}`,
|  | ExecutionOptions | options = `defaultExecutionOptions()`
| ) |  | -> detail::Stranded<typename std::decay<F>::type>
| inline

Definition at line 235 of file strand.hpp.

template<typename F >

auto qi::Strand::unwrappedSchedulerFor | ( | F && | func,
|  | boost::function< void()> | onFail = `{}`,
|  | ExecutionOptions | options = `defaultExecutionOptions()`
| ) |  | -> detail::StrandedUnwrapped<typename std::decay<F>::type>
| 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.

See Also
  schedulerFor for details.

Definition at line 248 of file strand.hpp.

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

- /home/opennao/work/release-2.8/sdk/libqi/qi/strand.hpp