Rapicorn - Experimental UI Toolkit - Source Code
13.07.0
|
AsyncSignal is a Signal type with support for std::future returns from handlers. More...
#include <aidasignal.hh>
Inherits AsyncSignal< SignalSignature >.
Classes | |
class | Connector |
Public Member Functions | |
AsyncSignal (const FutureFunction &method=FutureFunction()) | |
Signal constructor, supports a default callback as argument. | |
Connector | operator() () |
Retrieve a connector object with operator+= and operator-= to connect and disconnect signal handlers. |
AsyncSignal is a Signal type with support for std::future returns from handlers.
The API is genrally analogous to Signal, however handlers that return a std::future<ReturnValue> are supported via the connect_future() method, and emissions are handled differently. Note that even simple handlers are wrapped into std::promise/std::future constructs, which makes AsyncSignal emissions significantly slower than Signal.emit(). The emisison() method creates an Emission object, subject to a delete() call later on. The general idiom for using emission objects is as follows:
MySignal::Emission *emi = sig_my_signal.emission (args...); while (!emi->done()) { if (emi->pending()) emi->dispatch(); // this calls signal handlers if (emi->has_value()) use (emi->get_value()); // value return from a signal handler via resolved future else ThisThread::yield(); // allow for (asynchronous) signal handler execution } delete emi;
Multiple emission objects may be created and used at the same time, and deletion of an emission before done() returns true is also supported.