Repository navigation
Add blocking support for poll, timer, and work operations - #309
Conversation
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).
📝 WalkthroughWalkthroughThe 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
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches🧪 Generate unit tests (beta)
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 |
There was a problem hiding this comment.
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 | 🟡 MinorStale 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:@panicon 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.@panicis 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:.monotonicis fine here, but worth a brief comment why.In blocking mode this is single-threaded, so
.monotonicis sufficient — there's no concurrent observer that needs to seefunc(data)'s side effects ordered relative to the.completedstore. If the async path ever reuses this handler (or if cancellation polling gets added later), you'd need.releaseon the.completedstore. A one-line comment noting "blocking mode is single-threaded, no ordering needed" would save the next reader the same analysis.
Summary
net_pollandpipe_pollsupport in blocking mode usingpoll()with infinite timeouttimersupport in blocking mode usingos.time.sleep()worksupport in blocking mode by executing the function synchronouslyImplementation Details
pollForReadyhelperosnamespace (os.fs,os.net,os.time)Platform Support
net_poll: All platformspipe_poll: POSIX only (panics on Windows with clear error message)timer: All platformswork: All platformsTesting
All 356 tests pass, including specific tests for poll, timer, and work operations.