Repository navigation
Change timedWait functions to accept Timeout parameter - #239
Conversation
All timedWait functions now accept Timeout union instead of Duration, allowing support for duration-based, deadline-based, or no timeout. Changes: - Add Timeout.toDeadline() helper for converting duration to deadline - Update Waiter.timedWait to accept Timeout parameter - Update AutoCancel.set to accept Timeout parameter - Update all sync primitives (Condition, Semaphore, Notify, ResetEvent, Signal, Futex) - Add basic test for Futex.timedWait which was previously untested - Update all tests and documentation to use new Timeout syntax
📝 WalkthroughWalkthroughThis PR replaces 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.
Actionable comments posted: 0
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (5)
src/sync/ResetEvent.zig (1)
150-159: Update timedWait docs to reflect Timeout semantics.
The comment still describes a duration-only timeout.📝 Suggested doc tweak
-/// Like `wait()`, but returns `error.Timeout` if the event is not set within the -/// specified duration. The timeout is specified in nanoseconds. +/// Like `wait()`, but returns `error.Timeout` if the event is not set within the +/// specified timeout. `.none` waits indefinitely.src/sync/Notify.zig (1)
137-145: Update timedWait docs to reflect Timeout semantics.
The comment still says “duration in nanoseconds.”📝 Suggested doc tweak
-/// Like `wait()`, but returns `error.Timeout` if no signal is received within the -/// specified duration. The timeout is specified in nanoseconds. +/// Like `wait()`, but returns `error.Timeout` if no signal is received within the +/// specified timeout. `.none` waits indefinitely.src/sync/Condition.zig (1)
144-156: Update timedWait docs to match Timeout.
The comment still describes “duration in nanoseconds,” but the API now accepts.duration,.deadline, or.none. That’s misleading for users.✏️ Proposed doc tweak
-/// Like `wait()`, but will return `error.Timeout` if no signal is received -/// within the specified duration. -/// -/// The timeout is specified in nanoseconds. If a signal is received before -/// the timeout expires, the function returns successfully with the mutex held. +/// Like `wait()`, but will return `error.Timeout` if no signal is received +/// before the provided `Timeout` expires. +/// +/// The timeout can be duration-based (`.{ .duration = ... }`), deadline-based +/// (`.{ .deadline = ... }`), or `.none` to wait indefinitely. If a signal is +/// received before the timeout expires, the function returns successfully with +/// the mutex held.src/sync/Semaphore.zig (1)
109-125: Docs still describe duration-only timeouts.
The comment says “duration in nanoseconds,” but the API now acceptsTimeoutunion values. Update the docs to match.✏️ Proposed doc tweak
-/// Like `wait()`, but returns `error.Timeout` if no permit becomes available -/// within the specified duration. The timeout is specified in nanoseconds. +/// Like `wait()`, but returns `error.Timeout` if no permit becomes available +/// before the provided `Timeout` expires. +/// +/// The timeout can be duration-based (`.{ .duration = ... }`), deadline-based +/// (`.{ .deadline = ... }`), or `.none` to wait indefinitely.src/runtime/autocancel.zig (1)
251-262: Rename the test to match the new.nonesemantics.
The test name and comment still mentionDuration.max, but the new API uses.noneto disable.✏️ Proposed rename
-test "AutoCancel: set with Duration.max clears prior timer" { +test "AutoCancel: set with .none clears prior timer" { @@ - // Disable it with .max + // Disable it with .none
Summary
All
timedWaitfunctions now accept theTimeoutunion type instead ofDuration, providing consistent support for:.{ .duration = .fromMilliseconds(100) }).{ .deadline = timestamp }).none)Changes
Timeout.toDeadline()helper method for converting duration-based timeouts to deadline-based onesWaiter.timedWaitto acceptTimeoutparameterAutoCancel.setto acceptTimeoutparameterCondition,Semaphore,Notify,ResetEvent,Signal, andFutexFutex.timedWait(was previously untested)TimeoutsyntaxTest plan
Futex.timedWait