Repository navigation
Conversation
SPIKE of timing primitives. sleep(duration) pauses for the given duration and
returns early when its context is cancelled; timeout(duration) { ... } runs a
block under a deadline and yields null when the deadline wins, cancelling
in-flight sleeps and GraphQL requests.
Durations are Go duration strings ("300ms", "1.5s") as a stopgap; a proper
Duration scalar is the intended replacement.
loop now checks for cancellation between iterations, so a loop that never
touches the network can still be stopped by a timeout, a lost race, or a failing
{{ }} sibling.
Signed-off-by: Alex Suraci <[email protected]>
Deploying dang with
|
| Latest commit: |
44fd29d
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://557a7e38.dang-3kk.pages.dev |
| Branch Preview URL: | https://sleep-timeout.dang-3kk.pages.dev |
`dang fmt` splits multi-statement blocks and the long rescue clause onto
their own lines; the test was hand-written compactly, so `fmt/stale`
flagged it.
The formatter needed two passes to reach a fixed point here: the first
pass broke the timeout blocks inside a one-line `assert { ... }`, the
second then expanded the assert bodies too.
Signed-off-by: Alex Suraci <[email protected]>
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.
Spike of timing primitives for the stdlib. Split out of #179, where it was an unrelated commit.
What's here
sleep(duration: String!)pauses for the given duration, then returnsnull. It's cancelled along with the surrounding evaluation, e.g. when it loses a race or atimeoutexpires.timeout(duration: String!) { ... }evaluates the block under a deadline. It returns the block's value, ornullif the deadline wins. When the deadline wins, the block's in-flight work (sleeps, GraphQL requests, loops) is cancelled. Only the timeout's own deadline turns intonull. Errors raised in the block,break/return, and cancellation of a parent all pass through unchanged.loopnow checks for cancellation between iterations. Without that check, a loop that never touches the network couldn't be stopped by a timeout, a lost race, or a failing{{ }}sibling.Tests are in
tests/test_sleep.dang.Durations are a stopgap
Durations are plain Go duration strings (
"300ms","1.5s","5m") for now. We should probably add a properDurationscalar type:::cast, and literals coerced into aDuration!slotseconds/millisecondsDateTimeWe'd also add more Time/DateTime functions alongside it. #172 (the
DateTimescalar feature request) is the companion design. OnceDurationexists,sleepandtimeoutwould takeDuration!instead ofString!.Testing
I ran
go testfor every dang Go module (pkg/dang, tests, cmd/dang, …) and it passed: 1197 tests passed, 6 skipped because nvim and tree-sitter aren't installed. The run didn't use the usualdang:baseimage: that build is currently broken by an upstream apko SBOM error onlibLLVM-23, so I ran the tests on a plaingolangbase image instead. The LSP/editor tests that need the dang base image didn't run.