Use Browser File System generate a blob file to create a worker and run function in the worker, you can concurrent exec function in different workers.
To solve webpack problems with worker-loader,just like bundle size and window is not defined,etc.
npm install worker-run
import {run} from 'worker-run'
function a(){console.log(123);return 123}
run(a).then(val=>console.log(val))
When you set keepAlive to true,worker will run until page closed.
import {run} from 'worker-run'
function a(val){setInterval(()=>console.log(val),1000);return val+1}
run({exec:a,keepAlive:true},123).then(val=>console.log(val))
Callback will be called when worker received message event
import {run} from 'worker-run'
function a(val){setInterval(()=>console.log(val),1000);return val+1}
function b(event){console.log(event)}
run({exec:a,keepAlive:true,callback:b},123).then(val=>console.log(val))