This module includes basic implementations of pw_async’s Dispatcher and FakeDispatcher.


class BasicDispatcher : public pw::async::Dispatcher, public thread::ThreadCore#

BasicDispatcher is a generic implementation of Dispatcher.

Public Functions

void RunUntilIdle()#

Execute all runnable tasks and return without waiting.

void RunUntil(chrono::SystemClock::time_point end_time)#

Run the dispatcher until Now() has reached end_time, executing all tasks that come due before then.

void RunFor(chrono::SystemClock::duration duration)#

Run the dispatcher until duration has elapsed, executing all tasks that come due in that period.

void RequestStop()#

Stop processing tasks. If the dispatcher is serving a task loop, break out of the loop, dequeue all waiting tasks, and call their TaskFunctions with a PW_STATUS_CANCELLED status. If no task loop is being served, execute the dequeueing procedure the next time the Dispatcher is run.

void Run() override#

Run the dispatcher until RequestStop() is called. Overrides ThreadCore::Run() so that BasicDispatcher is compatible with pw::thread::Thread.

virtual void PostAt(Task &task, chrono::SystemClock::time_point time) override#

Post caller owned |task| to be run at |time|.

virtual void PostPeriodicAt(Task &task, chrono::SystemClock::duration interval, chrono::SystemClock::time_point start_time) override#

Post caller owned |task| to be run at |time| then rerun at a regular |interval|. |interval| must not be zero.

virtual bool Cancel(Task &task) override#

Returns true if |task| is succesfully canceled. If cancelation fails, the task may be running or completed. Periodic tasks may be posted once more after they are canceled.

inline virtual chrono::SystemClock::time_point now() override#

Returns the current time.


First, set the following GN variables:


Next, create a target that depends on //pw_async_basic:dispatcher:

pw_executable("hello_world") {
  sources = [ "" ]
  deps = [

Next, construct and use a BasicDispatcher.

#include "pw_async_basic/dispatcher.h"

void DelayedPrint(pw::async::Dispatcher& dispatcher) {
     printf("hello world\n");
  }, 5s);

int main() {
  pw::async::BasicDispatcher dispatcher;
  return 0;

Size Report#




No backend is selected.