Skip to content

Commit 2f46c0a

Browse files
committed
Merge branch 'true-async-api' into true-async
2 parents 7149b30 + f7825de commit 2f46c0a

File tree

8 files changed

+594
-583
lines changed

8 files changed

+594
-583
lines changed

docs/source/true_async_api/api-reference.rst

Lines changed: 62 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@
22
API Reference
33
###############
44

5-
This section provides comprehensive documentation for the TrueAsync API functions, macros, and data structures based on the actual implementation in ``Zend/zend_async_API.h``.
5+
This section provides comprehensive documentation for the TrueAsync API functions, macros, and data
6+
structures based on the actual implementation in ``Zend/zend_async_API.h``.
67

7-
******************
8+
*************
89
API Version
9-
******************
10+
*************
1011

1112
.. code:: c
1213
@@ -15,9 +16,9 @@ This section provides comprehensive documentation for the TrueAsync API function
1516
#define ZEND_ASYNC_API_VERSION_MINOR 4
1617
#define ZEND_ASYNC_API_VERSION_PATCH 0
1718
18-
********************
19+
*****************
1920
Core API Macros
20-
********************
21+
*****************
2122

2223
Enablement Check
2324
================
@@ -26,18 +27,18 @@ Enablement Check
2627
2728
ZEND_ASYNC_IS_ENABLED()
2829
29-
Returns ``true`` if async functionality is available, ``false`` otherwise.
30-
Always check this before using any async APIs.
30+
Returns ``true`` if async functionality is available, ``false`` otherwise. Always check this before
31+
using any async APIs.
3132

3233
.. code:: c
3334
3435
ZEND_ASYNC_REACTOR_IS_ENABLED()
3536
3637
Returns ``true`` if reactor (event loop) is available and functional.
3738

38-
*********************
39+
**********************
3940
Coroutine Operations
40-
*********************
41+
**********************
4142

4243
Coroutine Creation
4344
==================
@@ -52,11 +53,11 @@ Coroutine Creation
5253
5354
Creates and spawns new coroutines with various configuration options:
5455

55-
* ``ZEND_ASYNC_SPAWN()`` - Create coroutine with default settings
56-
* ``ZEND_ASYNC_SPAWN_WITH(scope)`` - Create coroutine within specific scope
57-
* ``ZEND_ASYNC_SPAWN_WITH_PROVIDER(scope_provider)`` - Use scope provider object
58-
* ``ZEND_ASYNC_SPAWN_WITH_PRIORITY(priority)`` - Set coroutine priority
59-
* ``ZEND_ASYNC_SPAWN_WITH_SCOPE_EX(scope, priority)`` - Both scope and priority
56+
- ``ZEND_ASYNC_SPAWN()`` - Create coroutine with default settings
57+
- ``ZEND_ASYNC_SPAWN_WITH(scope)`` - Create coroutine within specific scope
58+
- ``ZEND_ASYNC_SPAWN_WITH_PROVIDER(scope_provider)`` - Use scope provider object
59+
- ``ZEND_ASYNC_SPAWN_WITH_PRIORITY(priority)`` - Set coroutine priority
60+
- ``ZEND_ASYNC_SPAWN_WITH_SCOPE_EX(scope, priority)`` - Both scope and priority
6061

6162
**Priority levels:**
6263

@@ -89,8 +90,8 @@ Adds coroutine to execution queue for scheduling.
8990
9091
Suspends current coroutine execution:
9192

92-
* ``SUSPEND()`` - Normal suspension
93-
* ``RUN_SCHEDULER_AFTER_MAIN()`` - Suspend from main context
93+
- ``SUSPEND()`` - Normal suspension
94+
- ``RUN_SCHEDULER_AFTER_MAIN()`` - Suspend from main context
9495

9596
Coroutine Control
9697
=================
@@ -102,8 +103,8 @@ Coroutine Control
102103
103104
Resume coroutine execution:
104105

105-
* ``RESUME(coroutine)`` - Normal resume
106-
* ``RESUME_WITH_ERROR(coroutine, error, transfer_error)`` - Resume with exception
106+
- ``RESUME(coroutine)`` - Normal resume
107+
- ``RESUME_WITH_ERROR(coroutine, error, transfer_error)`` - Resume with exception
107108

108109
.. code:: c
109110
@@ -112,12 +113,12 @@ Resume coroutine execution:
112113
113114
Cancel coroutine execution:
114115

115-
* ``CANCEL()`` - Cancel with default safety
116-
* ``CANCEL_EX()`` - Cancel with explicit safety flag
116+
- ``CANCEL()`` - Cancel with default safety
117+
- ``CANCEL_EX()`` - Cancel with explicit safety flag
117118

118-
********************
119+
***********
119120
Scope API
120-
********************
121+
***********
121122

122123
Scope Creation
123124
==============
@@ -129,30 +130,30 @@ Scope Creation
129130
130131
Create new async scopes for coroutine isolation:
131132

132-
* ``NEW_SCOPE(parent)`` - Create scope with parent reference
133-
* ``NEW_SCOPE_WITH_OBJECT(parent)`` - Create scope backed by zend_object
133+
- ``NEW_SCOPE(parent)`` - Create scope with parent reference
134+
- ``NEW_SCOPE_WITH_OBJECT(parent)`` - Create scope backed by zend_object
134135

135136
Scope Flags
136137
===========
137138

138139
.. code:: c
139140
140141
#define ZEND_ASYNC_SCOPE_IS_CLOSED(scope)
141-
#define ZEND_ASYNC_SCOPE_IS_CANCELLED(scope)
142+
#define ZEND_ASYNC_SCOPE_IS_CANCELLED(scope)
142143
#define ZEND_ASYNC_SCOPE_IS_DISPOSING(scope)
143144
144145
Check scope status:
145146

146-
* ``IS_CLOSED`` - Scope has been closed
147-
* ``IS_CANCELLED`` - Scope was cancelled
148-
* ``IS_DISPOSING`` - Scope is being disposed
147+
- ``IS_CLOSED`` - Scope has been closed
148+
- ``IS_CANCELLED`` - Scope was cancelled
149+
- ``IS_DISPOSING`` - Scope is being disposed
149150

150-
********************
151+
***********
151152
Event API
152-
********************
153+
***********
153154

154155
Event Lifecycle
155-
================
156+
===============
156157

157158
All async events implement these core function pointers:
158159

@@ -163,7 +164,7 @@ All async events implement these core function pointers:
163164
typedef void (*zend_async_event_dispose_t)(zend_async_event_t *event);
164165
165166
Event State Checking
166-
=====================
167+
====================
167168

168169
.. code:: c
169170
@@ -172,7 +173,7 @@ Event State Checking
172173
Check if event has been closed.
173174

174175
Event Reference Counting
175-
=========================
176+
========================
176177

177178
.. code:: c
178179
@@ -199,9 +200,9 @@ Event Flags
199200
200201
Manipulate event flags.
201202

202-
********************
203+
*************
203204
Reactor API
204-
********************
205+
*************
205206

206207
Reactor Control
207208
===============
@@ -219,16 +220,16 @@ Poll Events
219220
220221
typedef enum {
221222
ASYNC_READABLE = 1,
222-
ASYNC_WRITABLE = 2,
223+
ASYNC_WRITABLE = 2,
223224
ASYNC_DISCONNECT = 4,
224225
ASYNC_PRIORITIZED = 8
225226
} async_poll_event;
226227
227228
Event flags for socket polling operations.
228229

229-
********************
230+
******************
230231
Signal Constants
231-
********************
232+
******************
232233

233234
.. code:: c
234235
@@ -243,9 +244,9 @@ Event flags for socket polling operations.
243244
244245
Cross-platform signal constants for async signal handling.
245246

246-
********************
247+
*******************
247248
Process Execution
248-
********************
249+
*******************
249250

250251
Execution Modes
251252
===============
@@ -260,9 +261,9 @@ Execution Modes
260261
ZEND_ASYNC_EXEC_MODE_SHELL_EXEC /* shell_exec() - buffer output */
261262
} zend_async_exec_mode;
262263
263-
***********************
264+
************************
264265
Future and Channel API
265-
***********************
266+
************************
266267

267268
Futures
268269
=======
@@ -284,9 +285,9 @@ Channels
284285
285286
Create channels for coroutine communication.
286287

287-
****************************
288+
*****************************
288289
API Context Switch Handlers
289-
****************************
290+
*****************************
290291

291292
Registration
292293
============
@@ -299,7 +300,7 @@ Registration
299300
);
300301
301302
bool zend_coroutine_remove_switch_handler(
302-
zend_coroutine_t *coroutine,
303+
zend_coroutine_t *coroutine,
303304
uint32_t handler_index
304305
);
305306
@@ -329,9 +330,9 @@ Handler Function Type
329330
330331
Returns ``true`` to keep handler, ``false`` to remove it after execution.
331332

332-
********************
333+
*******************
333334
Utility Functions
334-
********************
335+
*******************
335336

336337
System Management
337338
=================
@@ -368,12 +369,12 @@ Exception Handling
368369
369370
Spawn coroutine specifically for throwing an exception within a scope.
370371

371-
***********************
372+
**********************
372373
API Error Management
373-
***********************
374+
**********************
374375

375376
API Exception Classes
376-
======================
377+
=====================
377378

378379
.. code:: c
379380
@@ -388,12 +389,12 @@ API Exception Classes
388389
389390
Get class entries for async-related classes and exceptions.
390391

391-
********************
392+
************
392393
Data Types
393-
********************
394+
************
394395

395396
Platform Types
396-
===============
397+
==============
397398

398399
.. code:: c
399400
@@ -411,13 +412,13 @@ Platform Types
411412
412413
Cross-platform type definitions for file descriptors, processes, and sockets.
413414

414-
************************
415+
********************
415416
API Best Practices
416-
************************
417+
********************
417418

418-
1. **Always check enablement** with ``ZEND_ASYNC_IS_ENABLED()`` before using APIs
419-
2. **Use appropriate scopes** for coroutine isolation
420-
3. **Handle reference counting** properly with event objects
421-
4. **Register cleanup handlers** using context switch handlers
422-
5. **Check reactor availability** before using event-based operations
423-
6. **Use priority levels** appropriately for coroutine scheduling
419+
#. **Always check enablement** with ``ZEND_ASYNC_IS_ENABLED()`` before using APIs
420+
#. **Use appropriate scopes** for coroutine isolation
421+
#. **Handle reference counting** properly with event objects
422+
#. **Register cleanup handlers** using context switch handlers
423+
#. **Check reactor availability** before using event-based operations
424+
#. **Use priority levels** appropriately for coroutine scheduling

docs/source/true_async_api/architecture.rst

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,28 +3,25 @@
33
##############
44

55
The TrueAsync API follows a clean separation-of-concerns architecture that splits API definition
6-
from implementation. This design enables modularity, testability, and support for multiple
7-
backend implementations.
6+
from implementation. This design enables modularity, testability, and support for multiple backend
7+
implementations.
88

99
The **True Async API** is divided into three main functional blocks:
1010

11-
- **Scheduler**
12-
Manages coroutines and the main event loop.
13-
14-
- **Reactor**
15-
Handles everything related to input/output (I/O), including sockets, timers, and file descriptors.
16-
17-
- **Thread Pool**
18-
Allows execution of blocking or heavy tasks in a thread pool.
11+
- **Scheduler** Manages coroutines and the main event loop.
12+
- **Reactor** Handles everything related to input/output (I/O), including sockets, timers, and file
13+
descriptors.
14+
- **Thread Pool** Allows execution of blocking or heavy tasks in a thread pool.
1915

2016
---
2117

2218
## Implementation Flexibility
2319

24-
The True Async API provides clearly separated interfaces for each block, allowing them to be implemented independently—even across different PHP extensions. For example:
20+
The True Async API provides clearly separated interfaces for each block, allowing them to be
21+
implemented independently—even across different PHP extensions. For example:
2522

26-
- The Scheduler can be implemented as part of the PHP core.
27-
- The Reactor can be implemented in a separate extension using `libuv`.
28-
- The Thread Pool can be based on native threads or a library like `pthreads`.
23+
- The Scheduler can be implemented as part of the PHP core.
24+
- The Reactor can be implemented in a separate extension using `libuv`.
25+
- The Thread Pool can be based on native threads or a library like `pthreads`.
2926

30-
This approach gives developers maximum flexibility and control over asynchronous execution.
27+
This approach gives developers maximum flexibility and control over asynchronous execution.

0 commit comments

Comments
 (0)