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 {
11391139
11401140/// Declares under what conditions an operation should return `error.Timeout`.
11411141pub const Timeout = union(enum) {
1142 /// `.none` will wait forever
11421143 none,
11431144 duration: Clock.Duration,
11441145 deadline: Clock.Timestamp,
lib/std/Io/Threaded.zig-1
......@@ -11711,7 +11711,6 @@ fn nowWasi(clock: Io.Clock) Io.Timestamp {
1171111711
1171211712fn sleep(userdata: ?*anyopaque, timeout: Io.Timeout) Io.Cancelable!void {
1171311713 const t: *Threaded = @ptrCast(@alignCast(userdata));
11714 if (timeout == .none) return;
1171511714 if (use_parking_sleep) return parking_sleep.sleep(timeout);
1171611715 if (native_os == .wasi) return sleepWasi(t, timeout);
1171711716 if (@TypeOf(posix.system.clock_nanosleep) != void) return sleepPosix(timeout);