Skip to content
FutureBlitz

    Install

    Import std.time.timers

    std.time.timers

    Waiting and pacing: Timer, on the I/O thread's loop, for Tasks that are done after a while, which any thread can wait for; Deadline, a time to give up at, as blocking calls take one; FixedStep, for a game loop's updates at a fixed rate; RateLimiter, which lets so many things happen in so long; and Debounce, for acting once a burst of events has stopped. What reads the monotonic clock also takes an Instant, so code, and its tests, can give the time as a value.

    std/time/timers.fb

    Types

    Timer 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 soon 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.

    std/time/timers.fb, line 19

    • 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.

    Deadline struct

    Public Struct Deadline Implements Comparable, Hashable, Defaultable

    A time to give up at, on the monotonic clock, as blocking calls take one; or none, which is every Deadline's zero.

    std/time/timers.fb, line 79

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

      That long after now, or after the Instant. One too far to count is none.

    • Public Static Method After(time: Duration, now: Instant): Deadline static method #

      That long after now. One too far to count is none.

    • Public Static Method At(time: Instant): Deadline static method #

      At the Instant.

    • Public Static Method Never(): Deadline static method #

      None: it never passes.

    • Public Static Method DefaultValue(): Deadline static method #

      The value to start from, like 0 for a number, "" for a String, or an empty collection.

      Doc from std.core.interfaces.Defaultable.DefaultValue.

    • Public Property IsNever: Bool property #

      Whether it's none, which never passes.

    • Public Property Remaining: Duration property #

      How long is left before it, now or at the Instant: 0 once it's passed, and the longest Duration for none.

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

      How long is left before it at now: 0 once it's passed, and the longest Duration for none.

    • Public Property HasPassed: Bool property #

      Whether it's passed, now or at the Instant.

    • Public Method HasPassedAt(now: Instant): Bool method #

      Whether it's passed at now.

    • Operator <(a: Deadline, b: Deadline): Bool operator #

      The sooner Deadline is the lesser; none is after every time.

    • Operator ==(a: Deadline, b: Deadline): Bool operator #

      As == goes, two Deadlines of none are the same, whatever their time.

    • Public Method Hash(): UInt64 method #

      Its hash, the same for values that are equal.

      Doc from std.core.interfaces.Hashable.Hash.

    FixedStep class

    Public Class FixedStep

    A game loop's updates at a fixed rate, whatever the frames' lengths: Advance, or Tick, takes the time a frame took and gives how many steps to run, keeping what's left for the next, and Alpha says how far into the next step that is, for drawing between two steps' states.

    std/time/timers.fb, line 151

    • @PanicsAtCaller Public New(rate: Int) constructor #

      Steps at a rate of that many a second, which panics for one that isn't above 0.

    • @PanicsAtCaller Public New(step: Duration) constructor #

      Steps of that length, which panics for one that isn't above 0.

    • Public Property Step: Duration property #

      How long a step is, to the nearest nanosecond, and in seconds, for an update that takes them.

    • Public Property StepSeconds: Double property #

      How long a step is, in seconds.

    • @PanicsAtCaller Public Property MaxSteps: Int property #

      The most steps a frame gives, 8 unless it's set, so a long frame doesn't make the next one longer still: the whole steps past them are dropped, and the part of a step left over stays. One below 1 panics.

    • Public Property Alpha: Double property #

      How far into the next step the time left over is, from 0 up to 1.

    • Public Method Advance(elapsed: Duration): Int method #

      How many steps to run for a frame that took that long. A Duration below 0 counts as 0.

    • Public Method Tick(): Int method #

      How many steps to run for the time since the last Tick, now or at the Instant; the first Tick starts the clock and gives 0.

    • Public Method Tick(now: Instant): Int method #

      How many steps to run for the time from the last Tick to now; the first Tick starts the clock and gives 0.

    • Public Method Reset() method #

      Forgets the time left over and the last Tick.

    RateLimiter class

    Public Class RateLimiter

    Lets so many things happen in so long, as a bucket of that many tokens that refills one at a time, evenly, so a burst can take the bucket at once and then they go at the rate.

    std/time/timers.fb, line 251

    • @PanicsAtCaller Public New(count: Int, per: Duration) constructor #

      count every per, with a bucket of count tokens, or of burst, which panics for a count, per, or burst that isn't above 0.

    • @PanicsAtCaller Public New(count: Int, per: Duration, burst: Int) constructor #

      count tokens every per, with a bucket of burst, which panics for a count, per, or burst that isn't above 0.

    • Public Method TryTake(): Bool method #

      Takes a token, now or at the Instant, when there is one, and gives whether it did.

    • Public Method TryTake(now: Instant): Bool method #

      A bucket that won't be full for longer than an Instant counts is full at the last one.

    • Public Method UntilNext(): Duration method #

      How long it is, from now or the Instant, until there's a token to take.

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

      How long it is from now until there's a token to take.

    • Public Method Take() method #

      Takes a token, sleeping until there's one.

    Debounce class

    Public Class Debounce

    Acts once a burst of events has stopped: each Signal starts the delay again, and Ready says True once the delay has gone by since the latest, and then not again until another Signal.

    std/time/timers.fb, line 324

    • @PanicsAtCaller Public New(delay: Duration) constructor #

      A Debounce of that delay, which panics for one below 0.

    • Public Method Signal() method #

      An event, now or at the Instant.

    • Public Method Signal(now: Instant) method #

      An event at now.

    • Public Property IsPending: Bool property #

      Whether a Signal waits for its delay.

    • Public Method Ready(): Bool method #

      Whether to act, now or at the Instant: True once the delay has gone by since the latest Signal, which it then forgets.

    • Public Method Ready(now: Instant): Bool method #

      Whether to act at now: True once the delay has gone by since the latest Signal, which it then forgets.

    • Public Method Cancel() method #

      Forgets the latest Signal.

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