Skip to content

Add blocking support for poll, timer, and work operations - #309

Merged
lalinsky merged 1 commit into
mainfrom
blocking-poll-timer-work
Feb 9, 2026
Merged

lalinsky merged 1 commit into
mainfrom
blocking-poll-timer-work

Conversation

@lalinsky

@lalinsky lalinsky commented Feb 9, 2026

Copy link
Copy Markdown
Owner

Summary

  • Add net_poll and pipe_poll support in blocking mode using poll() with infinite timeout
  • Add timer support in blocking mode using os.time.sleep()
  • Add work support in blocking mode by executing the function synchronously

Implementation Details

  • Poll operations use the existing pollForReady helper
  • Timer handles all timeout types (none/duration/deadline)
  • Work executes synchronously and updates state atomically
  • Consolidated imports to use os namespace (os.fs, os.net, os.time)

Platform Support

  • net_poll: All platforms
  • pipe_poll: POSIX only (panics on Windows with clear error message)
  • timer: All platforms
  • work: All platforms

Testing

All 356 tests pass, including specific tests for poll, timer, and work operations.

Extends blocking mode to support more operation types:
- net_poll and pipe_poll: Wait for socket/pipe readiness using poll()
- timer: Sleep for specified duration using os.time.sleep()
- work: Execute work function synchronously in current thread

Note: pipe_poll is not supported on Windows (panics with error message).
@coderabbitai

coderabbitai Bot commented Feb 9, 2026 •

Copy link
Copy Markdown
Contributor
📝 Walkthrough

Walkthrough

The blocking module now exports four new operation types (NetPoll, PipePoll, Timer, Work) imported from completion.zig. Four handler functions were added to execute these operations synchronously instead of panicking. OS-level abstractions replaced internal fs/net references, with control flow routed through the new handlers.

Changes

Cohort / File(s) Summary
Blocking Operation Handlers
src/ev/blocking.zig
Added four handler implementations (handlePipePoll, handleNetPoll, handleTimer, handleWork) to replace panics. New public exports for NetPoll, PipePoll, Timer, and Work. Replaced internal abstractions with os.\* and time imports. Updated executeBlocking to dispatch to operation-specific handlers.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Poem

🔄 No more panics when blocking calls arrive,
Handlers route the flow where ops survive,
Pipes and nets now play by sync rules true,
Timers tick, work completes—the blocking came through.

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title directly matches the main changes: adding blocking support for poll, timer, and work operations, which aligns with the four new handlers (handlePipePoll, handleNetPoll, handleTimer, handleWork) and exported entities added.
Description check ✅ Passed The description accurately covers the implementation details, platform support constraints, and testing results for the blocking-mode support additions, matching the changeset scope.
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 blocking-poll-timer-work

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.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/ev/blocking.zig (1)

39-40: ⚠️ Potential issue | 🟡 Minor

Stale doc comment — timer and work are now supported.

Line 40 still says "Timer and async/work/group operations are not supported" but this PR adds exactly that support. Update it to reflect reality.

-/// Supports file, pipe, and socket operations (read/write use poll+I/O on POSIX).
-/// Timer and async/work/group operations are not supported (require event loop).
+/// Supports file, pipe, socket, timer, and work operations (read/write use poll+I/O on POSIX).
+/// Async and group operations are not supported (require event loop).
🧹 Nitpick comments (2)
src/ev/blocking.zig (2)

215-231: @panic on Windows is a hard crash — consider returning an error instead.

If a caller mistakenly triggers a pipe poll in blocking mode on Windows, the process dies. Returning an error via c.setError(error.Unsupported) (or similar) would let the caller handle it gracefully without a crash. @panic is fine for "this should never happen" invariants, but platform-unsupported operations feel more like a reportable error.

Suggested alternative
 fn handlePipePoll(c: *Completion) void {
     if (builtin.os.tag == .windows) {
-        `@panic`("Pipe poll not supported on Windows in blocking mode");
+        c.setError(error.Unsupported);
+        return;
     }

559-568: Atomic ordering: .monotonic is fine here, but worth a brief comment why.

In blocking mode this is single-threaded, so .monotonic is sufficient — there's no concurrent observer that needs to see func(data)'s side effects ordered relative to the .completed store. If the async path ever reuses this handler (or if cancellation polling gets added later), you'd need .release on the .completed store. A one-line comment noting "blocking mode is single-threaded, no ordering needed" would save the next reader the same analysis.

@lalinsky
lalinsky merged commit 0f6bb0c into main Feb 9, 2026
16 checks passed
@lalinsky
lalinsky deleted the blocking-poll-timer-work branch February 9, 2026 10:51
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