(budgetMs: number = DEFAULT_YIELD_BUDGET_MS)
| 40 | export const DEFAULT_YIELD_BUDGET_MS = 250; |
| 41 | |
| 42 | export function createYielder(budgetMs: number = DEFAULT_YIELD_BUDGET_MS): MaybeYield { |
| 43 | let last = Date.now(); |
| 44 | return function maybeYield(): Promise<void> | undefined { |
| 45 | if (Date.now() - last < budgetMs) return undefined; |
| 46 | return new Promise<void>((resolve) => |
| 47 | setImmediate(() => { |
| 48 | last = Date.now(); |
| 49 | resolve(); |
| 50 | }) |
| 51 | ); |
| 52 | }; |
| 53 | } |
no test coverage detected