Reference · The realistic Earth's pure parts
createGatefunction
A rate gate for the draw: asks that come faster than minMs apart become one, and the last ask is never lost, so a burst of changes costs one draw.
Import it
import { createGate } from "@johnmorrisdotca/chikyu-earth/realistic";
Definition
function createGate(minMs: number, fire: () => void, timers?: Timers): Gate
Parameters
| Name | Type | Description |
|---|---|---|
minMs | number | The least time between two runs, in milliseconds. |
fire | () => void | What to run. |
timers (optional) | Timers | A clock and timers; the browser's by default (a test passes its own). |
Returns
Gate
The gate: request() to ask, cancel() to forget a waiting run, setMinMs() to change the pace.
Examples
import { createGate } from "@johnmorrisdotca/chikyu-earth/realistic";
const gate = createGate(30, () => console.log("drawn"));
gate.request();
gate.request();
gate.request();
gate.cancel();drawnWhat it prints (run when this page was built)