Skip to content

Commit dcd329b

Browse files
committed
Add ErlangEventLoop architecture diagram to asyncio.md
1 parent 98f8066 commit dcd329b

1 file changed

Lines changed: 50 additions & 0 deletions

File tree

docs/asyncio.md

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,56 @@ The `ErlangEventLoop` is a custom asyncio event loop backed by Erlang's schedule
1313
- **Full GIL release during waits** - Python's Global Interpreter Lock is released while waiting for events
1414
- **Native Erlang scheduler integration** - I/O events are handled by BEAM's scheduler
1515

16+
### Architecture
17+
18+
```
19+
┌──────────────────────────────────────────────────────────────────────────────┐
20+
│ ErlangEventLoop Architecture │
21+
├──────────────────────────────────────────────────────────────────────────────┤
22+
│ │
23+
│ Python (asyncio) Erlang (BEAM) │
24+
│ ──────────────── ───────────── │
25+
│ │
26+
│ ┌──────────────────┐ ┌────────────────────────────────────┐ │
27+
│ │ ErlangEventLoop │ │ py_event_worker │ │
28+
│ │ │ │ │ │
29+
│ │ call_later() ──┼─{timer,ms,id}─▶│ erlang:send_after(ms, self, {}) │ │
30+
│ │ call_at() │ │ │ │ │
31+
│ │ │ │ ▼ │ │
32+
│ │ add_reader() ──┼──{add_fd,fd}──▶│ enif_select(fd, READ) │ │
33+
│ │ add_writer() │ │ │ │ │
34+
│ │ │ │ ▼ │ │
35+
│ │ │◀──{fd_ready}───│ handle_info({select, ...}) │ │
36+
│ │ │◀──{timeout}────│ handle_info({timeout, ...}) │ │
37+
│ │ │ │ │ │
38+
│ │ _run_once() │ └────────────────────────────────────┘ │
39+
│ │ │ │ │
40+
│ │ ▼ │ ┌────────────────────────────────────┐ │
41+
│ │ process pending │ │ py_event_router │ │
42+
│ │ callbacks │ │ │ │
43+
│ └──────────────────┘ │ Routes events to correct loop │ │
44+
│ │ based on resource backref │ │
45+
│ ┌──────────────────┐ └────────────────────────────────────┘ │
46+
│ │ erlang_asyncio │ │
47+
│ │ │ ┌────────────────────────────────────┐ │
48+
│ │ sleep() ──┼─{sleep_wait}──▶│ erlang:send_after() + cond_wait │ │
49+
│ │ gather() │ │ │ │
50+
│ │ wait_for() │◀──{complete}───│ pthread_cond_broadcast() │ │
51+
│ │ create_task() │ └────────────────────────────────────┘ │
52+
│ └──────────────────┘ │
53+
│ │
54+
└──────────────────────────────────────────────────────────────────────────────┘
55+
```
56+
57+
**Components:**
58+
59+
| Component | Role |
60+
|-----------|------|
61+
| `ErlangEventLoop` | Python asyncio event loop using Erlang for I/O and timers |
62+
| `py_event_worker` | Erlang gen_server managing FDs and timers for a Python context |
63+
| `py_event_router` | Routes timer/FD events to the correct event loop instance |
64+
| `erlang_asyncio` | High-level asyncio-compatible API with direct Erlang integration |
65+
1666
## Usage
1767

1868
```python

0 commit comments

Comments
 (0)