(parser: Parser, source: string, budgetMs = REQUEST_PARSE_BUDGET_MS)
| 64 | * of whatever file that is. |
| 65 | */ |
| 66 | export function parseWithinBudget(parser: Parser, source: string, budgetMs = REQUEST_PARSE_BUDGET_MS): Tree | null { |
| 67 | const deadline = Date.now() + budgetMs; |
| 68 | // The runtime hands the callback's return value to the parser: `true` cancels. |
| 69 | const cancel = (() => Date.now() > deadline) as unknown as () => void; |
| 70 | const tree = parser.parse(source, null, { progressCallback: cancel }) ?? null; |
| 71 | if (!tree) parser.reset(); |
| 72 | return tree; |
| 73 | } |
| 74 | |
| 75 | /** The message a parse that ran past its budget records, as the parse pool words its own timeout. */ |
| 76 | export function parseTimeoutMessage(budgetMs: number): string { |
no test coverage detected