Skip to content

Commit b1e599a

Browse files
committed
fix: use macrotask state boundary in thread statequeue (#2116)
I initially thought a microtask boundary was sufficient, but with wasm breakpoints with no symbols (where we resume synchronously) I observed that sometimes the queued `resume` would not be dequeued before the next paused event was handled. So this moves it to a full macrotask.
1 parent ce5dfbb commit b1e599a

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

src/adapter/threads.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,9 +145,10 @@ class StateQueue {
145145

146146
public async enqueue<T>(operation: string, fn: () => Promise<T>) {
147147
// If we would no-op the task because it's already ongoing, make sure we flush
148-
// microtasks first to avoid a race https://github.com/microsoft/vscode/issues/204581
148+
// tasks first to avoid a race https://github.com/microsoft/vscode/issues/204581
149+
// This initially flushed microtasks, but that wasn't always sufficient.
149150
if (this.queue?.operation === operation) {
150-
await new Promise<void>(r => queueMicrotask(r));
151+
await new Promise<void>(r => setTimeout(r));
151152
}
152153

153154
if (!this.queue || this.queue.operation !== operation) {

0 commit comments

Comments
 (0)