Skip to content

Commit

Permalink
terminate on success
Browse files Browse the repository at this point in the history
  • Loading branch information
UziTech committed Apr 25, 2019
1 parent 888a610 commit 431da38
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions docs/USING_ADVANCED.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ parentPort.on('message', (markdownString) => {
// index.js

const { Worker } = require('worker_threads');
const markedWorker = new Worker('markedWorker.js');
const markedWorker = new Worker('./markedWorker.js');

const markedTimeout = setTimeout(() => {
markedWorker.terminate();
Expand All @@ -110,6 +110,7 @@ const markedTimeout = setTimeout(() => {
markedWorker.on('message', (html) => {
clearTimeout(markedTimeout);
console.log(html);
markedWorker.terminate();
});

markedWorker.postMessage(markdownString);
Expand All @@ -122,7 +123,8 @@ markedWorker.postMessage(markdownString);

importScripts('path/to/marked.min.js');

onmessage = (markdownString) => {
onmessage = (e) => {
var markdownString = e.data
postMessage(marked(markdownString));
};
```
Expand All @@ -136,9 +138,11 @@ var markedTimeout = setTimeout(() => {
throw new Error('Marked took too long!');
}, timeoutLimit);
markedWorker.onmessage = (html) => {
markedWorker.onmessage = (e) => {
var html = e.data;
clearTimeout(markedTimeout);
console.log(html);
markedWorker.terminate();
};
markedWorker.postMessage(markdownString);
Expand Down

0 comments on commit 431da38

Please sign in to comment.