-
Notifications
You must be signed in to change notification settings - Fork 171
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
When sending a payload, prefix it with its length. Then on the receiving end, we read the length and the entire buffer in chunks.
- Loading branch information
Showing
2 changed files
with
136 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import assert from 'tjs:assert'; | ||
import path from 'tjs:path'; | ||
|
||
|
||
const data = { | ||
x: new Array(65536).fill('x').join(''), | ||
y: new Array(65536).fill('y').join(''), | ||
z: 1234 | ||
}; | ||
const w = new Worker(path.join(import.meta.dirname, 'helpers', 'worker-echo.js')); | ||
const timer = setTimeout(() => { | ||
w.terminate(); | ||
assert.fail('Timeout out waiting for worker'); | ||
}, 10000); | ||
w.onmessage = event => { | ||
clearTimeout(timer); | ||
const recvData = event.data; | ||
assert.eq(data.x, recvData.x, 'Message received matches'); | ||
assert.eq(data.y, recvData.y, 'Message received matches'); | ||
assert.eq(data.z, recvData.z, 'Message received matches'); | ||
w.terminate(); | ||
}; | ||
w.onmessageerror = event => { | ||
//console.log('ERROR', event); | ||
}; | ||
w.postMessage(data); |