@mcjxy/task-pool
Version:
Easy way to manage a pool of workers, support cluster mode(run tasks in different process), thread mode(run tasks in different thread) and normal mode(run tasks in current thread)!
17 lines (14 loc) • 367 B
JavaScript
;
let count = 0;
module.exports = async (id, data) => {
return new Promise((resolve, reject) => {
setTimeout(() => {
console.log('worker', id, ': data', data, 'count:', count++);
if (parseInt('0' + data) % 2 === 1) {
reject(new Error(data));
} else {
resolve(data);
}
}, 1000);
});
};