MCPcopy
hub / github.com/statelyai/xstate / flushTimeouts

Method flushTimeouts

packages/core/src/SimulatedClock.ts:51–80  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

49 this.flushTimeouts();
50 }
51 private flushTimeouts() {
52 if (this._flushing) {
53 this._flushingInvalidated = true;
54 return;
55 }
56 this._flushing = true;
57
58 const sorted = [...this.timeouts].sort(
59 ([_idA, timeoutA], [_idB, timeoutB]) => {
60 const endA = timeoutA.start + timeoutA.timeout;
61 const endB = timeoutB.start + timeoutB.timeout;
62 return endB > endA ? -1 : 1;
63 }
64 );
65
66 for (const [id, timeout] of sorted) {
67 if (this._flushingInvalidated) {
68 this._flushingInvalidated = false;
69 this._flushing = false;
70 this.flushTimeouts();
71 return;
72 }
73 if (this.now() - timeout.start >= timeout.timeout) {
74 this.timeouts.delete(id);
75 timeout.fn.call(null);
76 }
77 }
78
79 this._flushing = false;
80 }
81 public increment(ms: number): void {
82 this._now += ms;
83 this.flushTimeouts();

Callers 2

setMethod · 0.95
incrementMethod · 0.95

Calls 1

nowMethod · 0.95

Tested by

no test coverage detected