npm.io
0.2.0 • Published 8 years ago

co-job

Licence
MIT
Version
0.2.0
Deps
1
Size
4 kB
Vulns
0
Weekly
0

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.

Keywords