Skip to content
FutureBlitz

    Install

    Import std.time.timers

    Timer

    std.time.timers

    class

    Public Class Timer

    Ticks of the monotonic clock, every so often, on the I/O thread's loop. A tick is never early, and comes as close after its time as the OS's timer lets it: within a couple of milliseconds on Linux and macOS, and within about 16 on Windows, whose timer ticks every 15.6 or so by default.

    Examples

    Local ticks = Timer.Every(10.Milliseconds, Instant.FromNanoseconds(0))
    Expect(ticks.UntilNext(Instant.FromNanoseconds(4_000_000)) == 6.Milliseconds)
    ticks.Stop()
    Expect(ticks.IsStopped)
    Timer.After(1.Milliseconds).Wait()

    std/time/timers.fb, line 32

    • Public Static Method After(time: Duration): Task static method #

      A Task that's done once that long has passed, which Await, or Wait() on any thread, waits for. Wait and RealWait's Tasks, by contrast, are the main thread's coroutines'.

    • @PanicsAtCaller Public Static Method Every(interval: Duration): Timer static method #

      A Timer that ticks every interval from now, or from the Instant, which panics for an interval that isn't above 0.

    • @PanicsAtCaller Public Static Method Every(interval: Duration, start: Instant): Timer static method #

      A Timer that ticks every interval from start, which panics for an interval that isn't above 0.

    • Public Property IsStopped: Bool property #

      Whether it's stopped.

    • @PanicsAtCaller Public Method Next(): Task method #

      A Task that's done at its next tick after now, so a tick that's gone by while nothing waited is skipped, not caught up on. A stopped Timer's panics.

    • Public Method UntilNext(now: Instant): Duration method #

      How long it is from now, the Instant, to its next tick.

    • Public Method Stop() method #

      Stops it, though a tick already asked for is still done.

    Report an issue with this page or with FutureBlitz on GitHub.