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.
-
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'.
-
A Timer that ticks every interval from now, or from the Instant, which panics for an
intervalthat isn't above 0. -
@PanicsAtCaller Public Static Method Every(interval: Duration, start: Instant): Timerstatic method #A Timer that ticks every
intervalfromstart, which panics for an interval that isn't above 0. -
Whether it's stopped.
-
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.
-
How long it is from
now, the Instant, to its next tick. -
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.
-
That long after now, or after the Instant. One too far to count is none.
-
That long after
now. One too far to count is none. -
At the Instant.
-
None: it never passes.
-
The value to start from, like 0 for a number, "" for a String, or an empty collection.
-
Whether it's none, which never passes.
-
How long is left before it, now or at the Instant: 0 once it's passed, and the longest Duration for none.
-
How long is left before it at
now: 0 once it's passed, and the longest Duration for none. -
Whether it's passed, now or at the Instant.
-
Whether it's passed at
now. -
The sooner Deadline is the lesser; none is after every time.
-
As == goes, two Deadlines of none are the same, whatever their time.
-
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.
-
Steps at a rate of that many a second, which panics for one that isn't above 0.
-
Steps of that length, which panics for one that isn't above 0.
-
How long a step is, to the nearest nanosecond, and in seconds, for an update that takes them.
-
How long a step is, in seconds.
-
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.
-
How far into the next step the time left over is, from 0 up to 1.
-
How many steps to run for a frame that took that long. A Duration below 0 counts as 0.
-
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.
-
How many steps to run for the time from the last Tick to
now; the first Tick starts the clock and gives 0. -
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.
-
countevery per, with a bucket ofcounttokens, or of burst, which panics for a count,per, or burst that isn't above 0. -
counttokens everyper, with a bucket ofburst, which panics for a count,per, orburstthat isn't above 0. -
Takes a token, now or at the Instant, when there is one, and gives whether it did.
-
A bucket that won't be full for longer than an Instant counts is full at the last one.
-
How long it is, from now or the Instant, until there's a token to take.
-
How long it is from
nowuntil there's a token to take. -
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.
-
A Debounce of that
delay, which panics for one below 0. -
An event, now or at the Instant.
-
An event at
now. -
Whether a Signal waits for its delay.
-
Whether to act, now or at the Instant: True once the delay has gone by since the latest Signal, which it then forgets.
-
Whether to act at
now: True once the delay has gone by since the latest Signal, which it then forgets. -
Forgets the latest Signal.
Report an issue with this page or with FutureBlitz on GitHub.