@@ -47,10 +47,10 @@ erlang.run(main())
4747│ │ _run_once() │ └────────────────────────────────────┘ │
4848│ │ │ │ │
4949│ │ ▼ │ ┌────────────────────────────────────┐ │
50- │ │ process pending │ │ py_event_router │ │
50+ │ │ process pending │ │ │ │
5151│ │ callbacks │ │ │ │
52- │ └──────────────────┘ │ Routes events to correct loop │ │
53- │ │ based on resource backref │ │
52+ │ └──────────────────┘ │ │ │
53+ │ │ │ │
5454│ ┌──────────────────┐ └────────────────────────────────────┘ │
5555│ │ asyncio (via │ │
5656│ │ erlang.run()) │ ┌────────────────────────────────────┐ │
@@ -68,8 +68,7 @@ erlang.run(main())
6868| Component | Role |
6969| -----------| ------|
7070| ` ErlangEventLoop ` | Python asyncio event loop using Erlang for I/O and timers |
71- | ` py_event_worker ` | Erlang gen_server managing FDs and timers for a Python context |
72- | ` py_event_router ` | Routes timer/FD events to the correct event loop instance |
71+ | ` py_event_worker ` | Erlang gen_server handling FDs, timers, and task processing |
7372| ` erlang.run() ` | Entry point to run asyncio code with the Erlang event loop |
7473
7574## Usage Patterns
@@ -541,13 +540,13 @@ py_nif:close_test_fd(Fd).
541540
542541## Integration with Erlang
543542
544- The event loop integrates with Erlang's message passing system through a router process:
543+ The event loop integrates with Erlang's message passing system through a worker process:
545544
546545``` erlang
547- % % Start the event router
546+ % % Start the event worker
548547{ok , LoopRef } = py_nif :event_loop_new (),
549- {ok , RouterPid } = py_event_router :start_link (LoopRef ),
550- ok = py_nif :event_loop_set_router (LoopRef , RouterPid ).
548+ {ok , WorkerPid } = py_event_worker :start_link (<< " worker " >>, LoopRef ),
549+ ok = py_nif :event_loop_set_worker (LoopRef , WorkerPid ).
551550```
552551
553552Events are delivered as Erlang messages, enabling the event loop to participate in BEAM's supervision trees and distributed computing capabilities.
@@ -598,27 +597,28 @@ t2.join()
598597
599598### Internal Architecture
600599
601- A shared router process handles timer and FD events for all loops :
600+ Each event loop has an associated worker process that handles timer and FD events:
602601
603602```
604603┌─────────────────────────────────────────────────────────────────┐
605- │ py_event_router (shared) │
604+ │ py_event_worker │
606605│ │
607606│ Receives: │
608607│ - Timer expirations from erlang:send_after │
609608│ - FD ready events from enif_select │
609+ │ - task_ready messages for processing tasks │
610610│ │
611- │ Dispatches to correct loop via resource backref │
611+ │ Dispatches events to the loop's pending queue │
612612└─────────────────────────────────────────────────────────────────┘
613- ▲ ▲ ▲
614- │ │ │
615- ┌────┴────┐ ┌────┴────┐ ┌────┴ ────┐
616- │ Loop A │ │ Loop B │ │ Loop C │
617- │ pending │ │ pending │ │ pending │
618- └─────────┘ └─────────┘ └─────────┘
613+ │
614+ ▼
615+ ┌─────── ────┐
616+ │ Loop │
617+ │ pending │
618+ └── ─────────┘
619619```
620620
621- Each loop has its own pending queue, ensuring callbacks are processed only by the loop that scheduled them. The shared router dispatches timer and FD events to the correct loop based on the capsule backref .
621+ Each loop has its own pending queue, ensuring callbacks are processed only by the loop that scheduled them. The worker dispatches timer, FD events, and tasks to the correct loop.
622622
623623## Erlang Timer Integration
624624
0 commit comments