On Github leechwin / slide-webworker
UI pending while JavaScript is executing
UI long pending while Heavy Weight JavaScript is executing
function fun1() { console.log("fun1"); setTimeout(fun2, 0); console.log("fun1-2"); fun3(); } function fun2() { console.log("fun2"); } function fun3() { console.log("fun3"); } fun1();Expect Result: fun1, fun2, fun1-2, fun3 ? Demo
Possible to WebWorker.
Loading Route...
// index.html <script> var worker = new Worker( 'worker.js' ); worker.onmessage = function ( event ) { // TODO::Update UI Logic }; worker.postMessage( values ); function stop() { worker.terminate(); } </script>
// worker.js // importScripts( ‘library1.js’, ‘library2.js’); onmessage = function ( event ) { // TODO:: Bussiness Logic postMessage( data ); }
// index.html <script> var worker = new SharedWorker('sharedWorker.js', 'workerName'); worker.port.onmessage = function ( event ) { console.log( event.data ); }; worker.port.postMessage( values ); </script>
// sharedWorker.js var globalConnections = 0; onconnect = function ( event ) { var port = event.ports[0]; globalConnections++; port.onmessage = function ( event ) { port. postMessage( globalConnections ); // port.close(); } }Demo