Runs a function in a thread
if (isMainThread) { runInThread(() => { // Your code here const sum = [1, 2, 3, 4].reduce((a, b) => a + b, 0); return sum; }).then(result => { console.log(`Result: ${result}`); }).catch(err => { console.error(err); });} Copy
if (isMainThread) { runInThread(() => { // Your code here const sum = [1, 2, 3, 4].reduce((a, b) => a + b, 0); return sum; }).then(result => { console.log(`Result: ${result}`); }).catch(err => { console.error(err); });}
The function to run in a thread
Runs a function in a thread