class EE::Scene::MainThreadExecutor¶
Overview¶
Executor that runs functions on the main (UI) thread. More…
#include <mainthreadexecutor.hpp> class MainThreadExecutor: public EE::Executor { public: // construction MainThreadExecutor(Node* dispatcher); MainThreadExecutor(const MainThreadExecutor&); ~MainThreadExecutor(); // methods MainThreadExecutor& operator=(const MainThreadExecutor&); virtual void execute(Function function); void shutdown(); size_t pending() const; };
Inherited Members¶
public: // typedefs typedef SmallUniqueFunction<void(), FunctionInlineSize> Function; // fields static constexpr std::size_t FunctionInlineSize = 64; // methods virtual void execute(Function function) = 0;
Detailed Documentation¶
Executor that runs functions on the main (UI) thread.
Functions are queued and drained in submission order by a single Node::runOnMainThread() runnable per batch, so bursts of continuations cost one scheduled action. Execution is always deferred to the next scene update, even when execute() is called from the main thread, which is what Task::then() requires.
The dispatcher node must outlive the executor, or shutdown() must be called before the node is destroyed. Destroying the executor drops queued functions that have not run yet (releasing what they own, for example abandoning the tasks of the resolvers they hold).
Methods¶
void shutdown()
Detaches the executor from its dispatcher node and drops the queued functions. Functions executed afterwards are dropped too. Call it before the dispatcher node is destroyed when work may still be executed on this executor (it must then outlive that work).
size_t pending() const
Returns:
Number of functions waiting for the main thread.