A Scheduler
is responsible for coordinating the processing of messages by one or more actors via their mailboxes. It's an abstract interface. Currently, the following concrete implementations exist:
ThreadPool
can coordinate an unlimited number of actors over any number of threads via a pool, preserving the following behaviors:
- Messages from each individual mailbox are processed in order
- Only a single message from a mailbox is processed at a time; there is no concurrency within a mailbox
Subject to these constraints, processing can happen on whatever thread in the pool is available.
Scheduler::GetCurrent()
is typically used to create a mailbox and ActorRef
for an object that lives on the main thread and is not itself wrapped an Actor
. The underlying implementation of this Scheduler should usually be a RunLoop
auto mailbox = std::make_shared<Mailbox>(*Scheduler::Get()); Actor<Worker> worker(threadPool, ActorRef<Foo>(*this, mailbox));
Definition at line 35 of file scheduler.hpp.
std::function<void()> mbgl::Scheduler::bindOnce |
( |
std::function< void()> |
| ) |
|
Returns a closure wrapping the given one.
When the returned closure is invoked for the first time, it schedules the given closure to this scheduler, the consequent calls of the returned closure are ignored.
If this scheduler is already deleted by the time the returnded closure is first invoked, the call is ignored.
template<typename TaskFn , typename ReplyFn >
void mbgl::Scheduler::scheduleAndReplyValue |
( |
const TaskFn & |
task, |
|
|
const ReplyFn & |
reply |
|
) |
| |
|
inline |
Enqueues the given |task| for execution into this scheduler's task queue and then enqueues the |reply| with the captured task result to the current task queue.
The |TaskFn| return type must be compatible with the |ReplyFn| argument type. Note: the task result is copied and passed by value.
Definition at line 61 of file scheduler.hpp.