mission-pipe
v1.0.0
Published
Mission-pipe is tool for executing Promise-based mission concurrently.
Downloads
10
Readme
Mission-pipe is tool for executing Promise-based mission concurrently.
const mpipe = new Mpipe({
maxPoolSize: 10,
endCallback: (abortedMissionQueue) => {
console.log(`${abortedMissionQueue.length} missions have been aborted`)
console.log('All the missions have been done')
}
})
const myMissionsData = Array.apply({}, Array(100)).map((v, i) => i + 1)
function missionEmiterMocker (v) {
return () => {
return new Promise((res, rej) => {
setTimeout(() => {
if (Math.random() > 0.8) rej(new Error('manual error'))
else {
res('amazing', v)
}
}, 4000 * Math.random())
})
}
}
myMissionsData.forEach((v) => {
mpipe.push(new Mission(
missionEmiterMocker(),
{
meta: {
name: 'fakeMission ' + v
},
timeout: 3000,
maxRetryTime: 3,
callback: (res, meta, retryInfo) => {
console.log(meta.name, 'mission resolved')
},
errorCallback: (err, meta, retryInfo) => {
console.log(err)
console.log(meta.name, 'mission errored', 'retryTimeLeft:', retryInfo.retryTimeLeft)
},
abortCallback: (meta, retryInfo) => {
console.log(meta.name, 'mission aborted')
}
}
))
})
mpipe.start() // start mission execution
mpipe.end() // When you are sure that all the missions have been pushed into Mpipe```