Adarsh Thakur

Web Workers in JavaScripts.

How can we achieve concurrency in Javascript?

let worker = new Worker('web-worker.js');
// main.js
let worker = new Worker('web-worker.js');
worker.addListener('message',(e) => {
console.log('Hey! Workers Said : ', e.data);
},false);
worker.postMessage('This message is from Parent to Web Worker');
// web-worker.js
self.addEventListener('message', function(e) {
self.postMessage(e.data);
}, false);

Explanation

Hey 👋, I am Adarsh, a Web Developer from 🇮🇳