Code
Hub
Workspaces
Following
Trending
Connect
MCP
copy
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
1
const
sleep = (ms) =>
new
Promise((res) => setTimeout(res, ms));
// <1>
2
3
function
asyncOnMessageWrap(fn) {
// <2>
4
return
async
function
(msg) {
5
postMessage(
await
fn(msg.data));
6
}
7
}
8
9
const
commands = {
10
async
square_sum(max) {
Callers
1
worker.js
File · 0.70
Calls
no outgoing calls
Tested by
no test coverage detected