@@ -29,33 +29,26 @@ Inspired by:
2929Async Macros and Functions
3030==========================
3131
32- The async macros and functions below help create asynchronous functions,
32+ The async macros and functions below help create asynchronous functions/blocks ,
3333manage state, and handle control flow.
3434
3535Macros
3636------
3737
3838- **AM_ASYNC_BEGIN(me) **
3939
40- Begins an asynchronous function and initializes the async state.
40+ Begins an asynchronous function/block and initializes the async state.
4141 It takes a pointer ``me `` to the ``struct am_async `` managing the async state.
4242
43- - **AM_ASYNC_EXIT() **
44-
45- Marks the end of the async function. This macro resets the async state
46- to the initial value, indicating that the function has completed.
47-
4843- **AM_ASYNC_END() **
4944
50- Ends the asynchronous function, ensuring that completed or unexpected
51- states are handled correctly. It internally calls ``AM_ASYNC_EXIT() ``
52- to reset the async state.
45+ Ends the asynchronous function/block.
5346
5447- **AM_ASYNC_AWAIT(cond) **
5548
5649 Awaits a specified condition ``cond `` before proceeding with execution.
57- If the condition is not met, the function returns and can be re-entered later.
58- This allows the async function to wait for external conditions without blocking.
50+ If the condition is not met, the function/block returns and can be re-entered later.
51+ This allows the async function/block to wait for external conditions without blocking.
5952
6053- **AM_ASYNC_CHAIN(call) **
6154
@@ -65,15 +58,15 @@ Macros
6558
6659- **AM_ASYNC_YIELD() **
6760
68- Yields control back to the caller without completing the function
69- This enables the async function to be resumed later from this point.
61+ Yields control back to the caller without completing the function/block
62+ This enables the async function/block to be resumed later from this point.
7063
7164Functions
7265---------
7366
7467- **void am_async_ctor(struct am_async *me) **
7568
76- Initializes an `struct am_async`` structure by setting its ``state `` field
69+ Initializes an `` struct am_async `` structure by setting its ``state `` field
7770 to ``AM_ASYNC_STATE_INIT ``. This prepares the structure to be used in
7871 an async function.
7972
@@ -84,48 +77,9 @@ Functions
8477Usage Example
8578=============
8679
87- The following example demonstrates how to use this async implementation in C.
88-
89- .. code-block :: c
90-
91- #include "async.h"
92-
93- struct my_async {
94- struct am_async async;
95- int foo;
96- };
97-
98- void async_function(struct my_async *me) {
99- AM_ASYNC_BEGIN(me);
100-
101- /* Await some condition before continuing */
102- AM_ASYNC_AWAIT(me->foo);
103-
104- /* Yield control back to the caller */
105- AM_ASYNC_YIELD();
106-
107- if (some_other_condition) {
108- /* Complete the function */
109- AM_ASYNC_EXIT();
110- }
111-
112- /* Await yet another condition */
113- AM_ASYNC_AWAIT(yet_another_condition());
114-
115- /* Complete the function */
116- AM_ASYNC_END();
117- }
118-
119- int main() {
120- struct my_async me;
121- am_async_ctor(&me);
122-
123- do {
124- async_function(&me)
125- } while (am_async_is_busy(&me))
126-
127- return 0;
128- }
80+ Check `async unit tests <https://github.com/adel-mamin/amast/blob/main/libs/async/test.c >`_ and
81+ `async example application <https://github.com/adel-mamin/amast/blob/main/apps/examples/async/main.c >`_
82+ for usage examples.
12983
13084Notes
13185=====
0 commit comments