MCPcopy Create free account
hub / github.com/MultithreadedJSBook/code-samples / asyncOnMessageWrap

Function asyncOnMessageWrap

ch2-patterns/worker.js:3–7  ·  view source on GitHub ↗
(fn)

Source from the content-addressed store, hash-verified

1const sleep = (ms) => new Promise((res) => setTimeout(res, ms)); // <1>
2
3function asyncOnMessageWrap(fn) { // <2>
4 return async function(msg) {
5 postMessage(await fn(msg.data));
6 }
7}
8
9const commands = {
10 async square_sum(max) {

Callers 1

worker.jsFile · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected