authorgravatar for bblack@wikimedia.orgBrandon Black <bblack@wikimedia.org> 2026-05-12 13:22:07-05:00
committergravatar for bblack@wikimedia.orgBrandon Black <bblack@wikimedia.org> 2026-08-07 17:50:12-05:00
log1182f06c1487149282f699d6265e7ef91e8a56ad
treefb33d5155d8a2c73704afd1bd4662da8e4644ddd
parent9787df9421ad9d3fcb08cc7b394656542b16cfae

Io: Fix Threaded.sleep(.none), doc Timeout.none

Timeout.none implicitly seems to mean indefinitely nearly everywhere I can see. However, Io.Threaded.sleep() has a short-circuit at the top which treats Timeout.none as effectively zero (no sleep at all), even though the per-target functions it calls afterwards would otherwise would honor .none correctly. This patch removes this (presumably erronenous) short-circuit and documents Timeout.none's meaning explicitly.

2 files changed, 1 insertions(+), 1 deletions(-)

lib/std/Io.zig+1
...@@ -1139,6 +1139,7 @@ pub const Duration = struct {...@@ -1139,6 +1139,7 @@ pub const Duration = struct {
11391139
1140/// Declares under what conditions an operation should return `error.Timeout`.1140/// Declares under what conditions an operation should return `error.Timeout`.
1141pub const Timeout = union(enum) {1141pub const Timeout = union(enum) {
1142 /// `.none` will wait forever
1142 none,1143 none,
1143 duration: Clock.Duration,1144 duration: Clock.Duration,
1144 deadline: Clock.Timestamp,1145 deadline: Clock.Timestamp,
lib/std/Io/Threaded.zig-1
...@@ -11711,7 +11711,6 @@ fn nowWasi(clock: Io.Clock) Io.Timestamp {...@@ -11711,7 +11711,6 @@ fn nowWasi(clock: Io.Clock) Io.Timestamp {
1171111711
11712fn sleep(userdata: ?*anyopaque, timeout: Io.Timeout) Io.Cancelable!void {11712fn sleep(userdata: ?*anyopaque, timeout: Io.Timeout) Io.Cancelable!void {
11713 const t: *Threaded = @ptrCast(@alignCast(userdata));11713 const t: *Threaded = @ptrCast(@alignCast(userdata));
11714 if (timeout == .none) return;
11715 if (use_parking_sleep) return parking_sleep.sleep(timeout);11714 if (use_parking_sleep) return parking_sleep.sleep(timeout);
11716 if (native_os == .wasi) return sleepWasi(t, timeout);11715 if (native_os == .wasi) return sleepWasi(t, timeout);
11717 if (@TypeOf(posix.system.clock_nanosleep) != void) return sleepPosix(timeout);11716 if (@TypeOf(posix.system.clock_nanosleep) != void) return sleepPosix(timeout);