• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1.. _module-pw_async_basic:
2
3==============
4pw_async_basic
5==============
6.. pigweed-module::
7   :name: pw_async_basic
8
9This module includes basic implementations of pw_async's Dispatcher and
10FakeDispatcher.
11
12---
13API
14---
15.. doxygenclass:: pw::async::BasicDispatcher
16   :members:
17   :protected-members:
18
19-----
20Usage
21-----
22First, set the following GN variables:
23
24.. code-block::
25
26   pw_async_TASK_BACKEND="$dir_pw_async_basic:task"
27   pw_async_FAKE_DISPATCHER_BACKEND="$dir_pw_async_basic:fake_dispatcher"
28
29
30Next, create a target that depends on ``//pw_async_basic:dispatcher``:
31
32.. code-block::
33
34   pw_executable("hello_world") {
35     sources = [ "hello_world.cc" ]
36     deps = [
37       "//pw_async_basic:dispatcher",
38     ]
39   }
40
41Next, construct and use a ``BasicDispatcher``.
42
43.. code-block:: cpp
44
45   #include "pw_async_basic/dispatcher.h"
46
47   void DelayedPrint(pw::async::Dispatcher& dispatcher) {
48     dispatcher.PostAfter([](auto&){
49        printf("hello world\n");
50     }, 5s);
51   }
52
53   int main() {
54     pw::async::BasicDispatcher dispatcher;
55     DelayedPrint(dispatcher);
56     dispatcher.RunFor(10s);
57     return 0;
58   }
59
60-----------
61Size Report
62-----------
63.. TODO: b/388905812 - Re-enable the size report.
64.. .. include:: docs_size_report
65.. include:: ../size_report_notice
66