The worker runs three lines of plain blocking code. Each ask() posts the question down a port along with a small piece of shared memory, then sleeps on that memory. Whoever holds the other end of the port writes the answer into it and wakes the worker. The worker never yields, so it cannot receive a message. It does not need to: the answer is already in its memory when it wakes. The other end can be you, or another worker doing slow asynchronous work, and the blocking code cannot tell.
// in the worker: no async, no await, no callback function ask(question) { const memory = new SharedArrayBuffer(516); port.postMessage({ question, memory }); Atomics.wait(new Int32Array(memory, 0, 1), 0, 0); // stops here return read(memory); } const name = ask("What is your name?"); // whoever holds the other end, whenever they are ready write(memory, "Ada"); Atomics.notify(new Int32Array(memory, 0, 1), 0);