Add Sleep.seconds!#460
Merged
Merged
Conversation
dmisiuk
force-pushed
the
issue-409-sleep-seconds
branch
from
July 24, 2026 16:14
a7eed63 to
e8500e9
Compare
Anton-4
approved these changes
Jul 25, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds
Sleep.seconds!, closes #409.Discussed on Zulip — @Anton-4 preferred
F64overU64so that one function covers whole and fractional durations without having to switch back tomillis!.Implementation
seconds!converts to milliseconds and delegates to the existingHost.sleep_millis!, so there are no host or glue changes.The conversion is the only subtle part, so it lives in a pure top-level helper,
millis_from_seconds, which keeps it unit-testable.F64.round_to_u64crashes on negative,NaN, infinite, and out-of-range values, which isn't acceptable for a signature with no error channel.F64.to_u64_tryrejects exactly that set, so the helper separates the cases by sign: a positive value reaching theErrbranch can only be one that overflowed the millisecond range.Edge-case behavior
This wasn't part of the Zulip discussion, so flagging it explicitly for review:
1.50.00040NaNinf, or beyondU64.highestmsU64.highestmsReturning immediately on negative and
NaNfollows Go'stime.Sleep. Happy to change either behavior if you'd prefer something different.Testing
Nine
expectblocks inplatform/Sleep.roccovermillis_from_secondsacross all three branches — the ordinary conversion, the negative/NaNcase, and saturation. Each was verified to fail when its expected value is altered, so they aren't vacuously green.Full
./scripts/test.pypasses — host build plus all examples.The effectful wrapper was also measured against a local build of the platform before being reduced to a one-liner:
1.5 → 1500 ms,0.25 → 253 ms,0 → 0 ms,-5 → 0 ms,NaN → 0 ms. The saturating branch can't be exercised at runtime, since it sleeps for roughly 584 million years; it is covered by theexpectonmillis_from_secondsinstead.examples/time.rocnow usesSleep.seconds!(1)in place ofSleep.millis!(1000)and its# 1000 ms = 1 secondcomment, which is the ergonomic problem the issue describes. Itsone-second-sleepcase asserts output shape rather than the duration value, soscripts/test_spec.jsonis unchanged.