Last active
October 7, 2021 13:05
-
-
Save raubin-kumar/21c2785e530678cf7852445ffab0004c to your computer and use it in GitHub Desktop.
Worker files
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
const timeWorker = new Worker("worker.js"); | |
timeWorker.postMessage({ type: "GET_CURRENT_DATE" }); | |
timeWorker.onmessage = (evt) => { | |
console.log(evt.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
const currentDateTimeWorker = () => { | |
setInterval(() => { | |
postMessage(new Date()); | |
}, 1000); | |
}; | |
currentDateTimeWorker(); |
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
const currentDateTimeWorker = () => { | |
setInterval(() => { | |
postMessage(new Date()); | |
}, 1000); | |
}; | |
currentDateTimeWorker(); |
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
const dateTimeWorker = new Worker("current-datetime-worker.js"); | |
worker.onmessage = (e) => { | |
console.log(e.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
const timeWorker = new Worker("worker.js"); | |
//Terminate time worker | |
timeworker.terminate(); |
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
self.onmessage = (evt) => { | |
if (evt.data && evt.data.type === "GET_CURRENT_DATE") { | |
postMessage(new Date()); | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment