Skip to content

Add future protocol to Timeout for use with select() - #233

Merged
lalinsky merged 2 commits into
mainfrom
timeout-future-protocol
Jan 23, 2026
Merged

lalinsky merged 2 commits into
mainfrom
timeout-future-protocol

Conversation

@lalinsky

Copy link
Copy Markdown
Owner

Summary

  • Adds future protocol methods (asyncWait, asyncCancelWait, getResult) to the Timeout type
  • Enables Timeout to be used directly in select() calls for timeout races
  • Includes test verifying timeout wins against a channel that never receives

Test plan

  • ./check.sh --filter "Timeout future" passes
  • ./check.sh --full passes (320/320 tests)

Enables Timeout to be used directly in select() calls, allowing
timeouts to race against other async operations like channel receives.
@coderabbitai

coderabbitai Bot commented Jan 23, 2026 •

Copy link
Copy Markdown
Contributor
📝 Walkthrough

Walkthrough

Adds select()-compatible async timeout support to the Timeout type: introduces WaitContext (holds an ev.Timer and wait_node), asyncWait/asyncCancelWait, a timerCallback, getResult, and a Result alias to wire timer-driven signaling into the runtime's wait node flow.

Changes

Cohort / File(s) Summary
Timeout async protocol
src/time.zig
Adds pub const Result = void, pub const WaitContext (with ev.Timer and wait_node), asyncWait(self, rt, wait_node, ctx), asyncCancelWait(self, rt, wait_node, ctx), getResult(self, ctx), and timerCallback to implement timer-based wait/cancel and wake wait nodes; wires timers into executor loop; adds test exercising timeout path.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~22 minutes

Possibly related PRs

Poem

⏳ Small timers set, the wait nodes sleep,
A callback taps the loop, no blocking deep.
Timeouts whisper, then loudly say "done",
Select wakes up — the race is won! 🎉

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title directly describes the main change: adding future protocol support to Timeout for use in select() calls.
Description check ✅ Passed The description is clearly related to the changeset, explaining what methods were added and why (enabling Timeout in select() calls), plus test verification.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch timeout-future-protocol

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Fix all issues with AI agents
In `@src/time.zig`:
- Around line 371-376: In Timeout.asyncCancelWait, explicitly null out the wait
node pointer before calling loop.clearTimer to prevent a previously queued
callback from seeing a stale ctx.wait_node; update the function to set
ctx.wait_node = null (or equivalent) prior to calling
loop.clearTimer(&ctx.timer) so the callback's guard if (ctx.wait_node) |node|
cannot observe a pointer to a destroyed/reused wait node and cancellation
semantics are explicit.

Comment thread src/time.zig Resolved
Prevents a queued callback from waking a stale/reused wait node.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant