redis-smq-common
Version:
Provides essential components and utilities shared across RedisSMQ packages.
33 lines • 995 B
JavaScript
export function parallel(operations, callback) {
if (operations.length === 0) {
return callback(null, []);
}
let completed = 0;
let failed = false;
const results = new Array(operations.length);
operations.forEach((operation, index) => {
try {
operation((err, result) => {
if (failed)
return;
if (err) {
failed = true;
return callback(err);
}
results[index] = result;
completed++;
if (completed === operations.length) {
return callback(null, results);
}
});
}
catch (error) {
if (failed)
return;
failed = true;
const err = error instanceof Error ? error : new Error(String(error));
return callback(err);
}
});
}
//# sourceMappingURL=parallel.js.map