Skip to content

Instantly share code, notes, and snippets.

@raubin-kumar
Last active Oct 7, 2021
Embed
What would you like to do?
Worker files
const timeWorker = new Worker("worker.js");
timeWorker.postMessage({ type: "GET_CURRENT_DATE" });
timeWorker.onmessage = (evt) => {
console.log(evt.data);
}
const currentDateTimeWorker = () => {
setInterval(() => {
postMessage(new Date());
}, 1000);
};
currentDateTimeWorker();
const currentDateTimeWorker = () => {
setInterval(() => {
postMessage(new Date());
}, 1000);
};
currentDateTimeWorker();
const dateTimeWorker = new Worker("current-datetime-worker.js");
worker.onmessage = (e) => {
console.log(e.data);
};
const timeWorker = new Worker("worker.js");
//Terminate time worker
timeworker.terminate();
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