co-job

0.2.0 • Public • Published

co-job

Run jobs in limited runners. Jobs can dynamicly be pushed in current runner

Build Status

Note: if job contains error it will break runner processing. So you should process error with try/catch in your job

Quick start

const co = require('co')
const coJob = require('co-job')
co(function * () {
  const runner = coJob(5)
  runner.push(function () {
    return 'result'
  })
  console.log(yield runner.end())
})

Dependency

API

constructor(limit: Number, options: Object): Runner

Return a job runner with limited cocurrency runners.

options:

  • retainResult: <boolean> retain the result when run runner.end(). Or it would be an empty array. Default: true

Runner.push(job: yieldable): void

push yieldable job into runner include Promise, generator and normal function

Runner.end(): Promise

return a Promise with final result for all jobs

Runner Event: 'done'

Emit when one of the yieldable job finished.

  • job result: <any>
  • job sequence: <int> present as the job id as the sequence the job pushed.

Runner Event: 'drain'

Emit when one of the cocurrency runner finished its job squence.

Readme

Keywords

Package Sidebar

Install

npm i co-job

Weekly Downloads

0

Version

0.2.0

License

MIT

Unpacked Size

4.01 kB

Total Files

4

Last publish

Collaborators

  • orangemi