Permalink
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
dom-examples/web-workers/simple-web-worker/worker.js /
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
11 lines (11 sloc)
352 Bytes
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
| onmessage = function(e) { | |
| console.log('Worker: Message received from main script'); | |
| const result = e.data[0] * e.data[1]; | |
| if (isNaN(result)) { | |
| postMessage('Please write two numbers'); | |
| } else { | |
| const workerResult = 'Result: ' + result; | |
| console.log('Worker: Posting message back to main script'); | |
| postMessage(workerResult); | |
| } | |
| } |