JSFiddle - React, Tailwind, and code Playground

by Derek Leung

JavaScript

/**
	Open up the console and look at the logs.
	The worker thread is not affected when the page is inactive.
*/

function createWorker(main){
	var blob = new Blob(
    	["(" + main.toString() + ")(self)"],
    	{type: "text/javascript"}
    );
    var blobUrl = window.URL.createObjectURL(blob);
    var worker = new Worker(blobUrl);
    window.URL.revokeObjectURL(blobUrl);
    
    return worker;
}

// Worker
var worker = createWorker(function(self){
    setInterval(function(){
        self.postMessage(Date.now());
    }, 250);
});
worker.onmessage = function(e) {
    console.log("Worker: " + e.data);
}

// setInterval
setInterval(function(){
	console.log("setInterval: " + Date.now());
}, 250);