Sample code to create a web worker under Deno
Created
May 13, 2020 09:04
-
-
Save JWebCoder/3b15ad0b0586cb1d875919ebe2d1785f to your computer and use it in GitHub Desktop.
Deno web worker example
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
var myWorker = new Worker('./worker.ts', { | |
type: 'module' | |
}); | |
myWorker.postMessage('I am you father') | |
// @ts-ignore: deno typings | |
myWorker.addEventListener('message', (event: MessageEvent) => { | |
console.log(`Received message from worker: ${event.data}`) | |
}) |
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
// @ts-ignore: deno typings | |
addEventListener('message', (event: MessageEvent) => { | |
console.log(`You are my father: ${event.data}`) | |
// @ts-ignore: deno typings | |
postMessage('Hello father') | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment