Skip to content

Commit

Permalink
feat: add duration side condition for repeating timer
Browse files Browse the repository at this point in the history
  • Loading branch information
hargoniX committed Jan 7, 2025
1 parent a5b05eb commit 52d5c1e
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/Std/Internal/Async/Timer.lean
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ Setup up an `Interval` that waits for `duration` milliseconds.
This function only initializes but does not yet start the timer.
-/
@[inline]
def mk (duration : Std.Time.Millisecond.Offset) : IO Interval := do
def mk (duration : Std.Time.Millisecond.Offset) (_ : 0 < duration := by decide) : IO Interval := do
let native ← Internal.UV.Timer.mk duration.toInt.toNat.toUInt64 true
return ofNative native

Expand Down
6 changes: 3 additions & 3 deletions tests/lean/run/async_surface_sleep.lean
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def oneSleep : IO Unit := do
assert! (← task.block) == 37
where
go : IO (AsyncTask Nat) := do
let interval ← Interval.mk BASE_DURATION
let interval ← Interval.mk BASE_DURATION sorry
(← interval.tick).mapIO fun _ => do
interval.stop
return 37
Expand All @@ -73,7 +73,7 @@ def doubleSleep : IO Unit := do
assert! (← task.block) == 37
where
go : IO (AsyncTask Nat) := do
let interval ← Interval.mk BASE_DURATION
let interval ← Interval.mk BASE_DURATION sorry
(← interval.tick).bindIO fun _ => do
(← interval.tick).mapIO fun _ => do
interval.stop
Expand All @@ -84,7 +84,7 @@ def resetSleep : IO Unit := do
assert! (← task.block) == 37
where
go : IO (AsyncTask Nat) := do
let interval ← Interval.mk BASE_DURATION
let interval ← Interval.mk BASE_DURATION sorry
(← interval.tick).bindIO fun _ => do
let waiter ← interval.tick
interval.reset
Expand Down

0 comments on commit 52d5c1e

Please sign in to comment.