mission-pipe

1.0.0 • Public • Published

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```

Readme

Keywords

none

Package Sidebar

Install

npm i mission-pipe

Weekly Downloads

0

Version

1.0.0

License

MIT

Unpacked Size

11.5 kB

Total Files

4

Last publish

Collaborators

  • 07akioni