playing with workers
This commit is contained in:
parent
6eec4277c1
commit
0006f6483d
4 changed files with 38 additions and 41 deletions
17
packages/core/cyclistworker.js
Normal file
17
packages/core/cyclistworker.js
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
const ports = [];
|
||||
|
||||
self.onconnect = function (ev) {
|
||||
let port = ev.ports[0];
|
||||
port.onmessage = (e) => {
|
||||
setTimeout(() => {
|
||||
ports.forEach((p) => p.postMessage([e.data, ev.ports.length]));
|
||||
}, 300);
|
||||
};
|
||||
port.start();
|
||||
ports.push(port);
|
||||
};
|
||||
self.onmessage = ({ data: { question } }) => {
|
||||
self.postMessage({
|
||||
answer: 42,
|
||||
});
|
||||
};
|
||||
Loading…
Add table
Add a link
Reference in a new issue