* The dispatch loop asynchronously processes items in the async queue in order, and ensures that tasks are dispatched in the * order they were inserted.
()
| 2568 | * order they were inserted. |
| 2569 | */ |
| 2570 | private static async dispatch() { |
| 2571 | // reset the promise for the dispatcher |
| 2572 | DefaultClient.dispatching.reset(); |
| 2573 | |
| 2574 | do { |
| 2575 | // ensure that this is OK to start working |
| 2576 | await this.isStarted; |
| 2577 | |
| 2578 | // pick items up off the queue and run then one at a time until the queue is empty |
| 2579 | const [promise, task] = DefaultClient.queue.shift() ?? []; |
| 2580 | if (is.promise(promise)) { |
| 2581 | try { |
| 2582 | promise.resolve(task ? await task() : undefined); |
| 2583 | } catch (e) { |
| 2584 | console.log(e); |
| 2585 | promise.reject(e); |
| 2586 | } |
| 2587 | } |
| 2588 | } while (DefaultClient.queue.length); |
| 2589 | |
| 2590 | // unblock anything that is waiting for the dispatcher to empty |
| 2591 | this.dispatching.resolve(); |
| 2592 | } |
| 2593 | |
| 2594 | private static async withLspCancellationHandling<T>(task: () => Promise<T>, token: vscode.CancellationToken): Promise<T> { |
| 2595 | let result: T; |