(parser: Parser, source: string, budgetMs = REQUEST_PARSE_BUDGET_MS)
| 16 | |
| 17 | /** `parser.parse(source)`, or null when it runs past the budget. */ |
| 18 | export function parseWithinBudget(parser: Parser, source: string, budgetMs = REQUEST_PARSE_BUDGET_MS): Tree | null { |
| 19 | const deadline = Date.now() + budgetMs; |
| 20 | // The runtime hands the callback's return value to the parser: `true` cancels. |
| 21 | const cancel = (() => Date.now() > deadline) as unknown as () => void; |
| 22 | return parser.parse(source, null, { progressCallback: cancel }) ?? null; |
| 23 | } |
no test coverage detected