(gen: Generator<T>, timeLimitMs: number)
| 112 | this.name = 'CancellationError'; |
| 113 | if (cause === 'iteration-limit-exceeded') _iterationLimitCancellations += 1; |
| 114 | } |
| 115 | } |
| 116 | |
| 117 | /** |
| 118 | * Throw a `CancellationError` if `deadline` (an absolute timestamp in |
| 119 | * milliseconds, or a `DeadlineFrame`, i.e. `engine._deadline` / |
| 120 | * `engine._deadlineFrame`) has passed. |
| 121 | * |
| 122 | * When passed a `DeadlineFrame`, the thrown error carries `attribution` |
| 123 | * (the frame's `owner`) and `spans` so the catching code can tell which |
| 124 | * budget fired. |
| 125 | * |
| 126 | * Call this periodically from long-running loops that cannot be expressed |
| 127 | * as generators (where `run()`/`runAsync()` would apply). In tight loops, |
| 128 | * amortize the `Date.now()` cost with a stride counter: |
| 129 | * |
| 130 | * if ((++count & 0x3ff) === 0) checkDeadline(ce._deadlineFrame); |
| 131 | */ |
| 132 | export function checkDeadline( |
| 133 | deadline: number | DeadlineFrame | undefined |
| 134 | ): void { |
| 135 | if (deadline === undefined) return; |
no test coverage detected