Repository navigation
Add Runtime.runUntilComplete() convenience method - #19
Conversation
Implements a convenience method that combines spawn() + run() + result() into a single call, similar to Python's asyncio.run() and Rust's tokio::block_on(). This simplifies the common pattern of spawning a single main task and running the event loop until completion. The method properly handles error propagation from spawn(), run(), and the task itself. Changes: - Add runUntilComplete() method to Runtime - Add ReturnPayload() helper to extract payload type from error unions - Update single-task tests to use the simpler API - Update examples/sleep.zig to demonstrate the simplified usage Multi-task tests (server/client patterns) continue to use the existing spawn() + run() pattern as they require concurrent task execution.
WalkthroughConsolidated task execution by introducing Runtime.runUntilComplete and updating tests/examples to use it instead of manual spawn/run/result patterns. Added a helper to compute return payload types. No public API changes except the new Runtime method. Changes
Sequence Diagram(s)sequenceDiagram
autonumber
actor Caller as Test/Example
participant RT as Runtime
participant EL as Event Loop
participant Task as Spawned Task
Caller->>RT: runUntilComplete(func, args, options)
RT->>RT: spawn(func, args)
alt spawn error
RT-->>Caller: error
else spawned
RT->>EL: run()
EL->>Task: execute until completion
alt task error
Task-->>EL: error
EL-->>RT: error
RT-->>Caller: error
else success
Task-->>EL: payload
EL-->>RT: payload
RT-->>Caller: payload
end
end
note right of RT: Combines spawn + run + result
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Poem
Pre-merge checks and finishing touches✅ Passed checks (3 passed)
✨ Finishing touches🧪 Generate unit tests (beta)
📜 Recent review detailsConfiguration used: CodeRabbit UI Review profile: CHILL Plan: Pro 📒 Files selected for processing (6)
🔇 Additional comments (4)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Make backend waker responsible for draining: - Move drain() calls from loop.processAsyncHandles() to backend tick() methods - Backends now own and control their waker lifecycle Rename async_impl to waker: - Rename AsyncImpl struct to Waker across all backends (poll, kqueue, epoll) - Change field from optional async_impl to non-optional waker - Simplify code by removing unnecessary null checks Remove redundant has_fds checks: - Poll and epoll backends no longer need to check if waker exists - Waker is always initialized and available
* Add loongarch64 architecture support * Add loongarch64 CI test * Add sp and fp to loongarch64 clobber list
Summary
Implements a convenience method that combines
spawn() + run() + result()into a single call, similar to Python'sasyncio.run()and Rust'stokio::block_on().This simplifies the common pattern of spawning a single main task and running the event loop until completion.
Changes
runUntilComplete()method to Runtime (src/runtime.zig)ReturnPayload()helper to extract payload type from error unionsAPI Design
Before:
After:
Error Handling
The method returns
!ReturnPayload(func)which properly merges:spawn()(allocation, etc.)run()(event loop errors)Multi-task tests (server/client patterns) continue to use the existing
spawn() + run()pattern as they require concurrent task execution.Testing
All 41 tests pass ✓
Summary by CodeRabbit