funthreads
Version:
A lightweight tool built on top of Node.js worker_threads, enabling multithreading.
24 lines (19 loc) • 406 B
JavaScript
const { executeInThread } = require('funthreads');
// this will be executed in a dedicated thread
function task() {
// return is important!
return new Promise((resolve) => {
setTimeout(() => {
resolve('Done!');
}, 3000);
});
}
async function start() {
try {
const data = await executeInThread(task);
console.log(data);
} catch (err) {
console.log(err);
}
}
start();