# co-job

> co-job ====== Run jobs in limited runners. Jobs can dynamicly be pushed in current runner

Latest version **0.2.0** (published 2018-02-11) · MIT license · 0 weekly downloads

## Install

```sh
npm install co-job
pnpm add co-job
yarn add co-job
bun add co-job
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.2.0 |
| Published | 2018-02-11 |
| First published | 2018-02-08 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 3.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Orange Mi |
| Maintainers | orangemi |
| Keywords | co, generator |

## Links

- npm: https://www.npmjs.com/package/co-job
- Repository: https://github.com/orangemi/co-job
- Homepage: https://github.com/orangemi/co-job#readme
- Issues: https://github.com/orangemi/co-job/issues
- npm.io page: https://npm.io/package/co-job

## Dependencies (1)

- [co](https://npm.io/package/co.md) ^4.6.0

## Alternatives

- [flatbuffers](https://npm.io/package/flatbuffers.md) — 6.0M weekly downloads
- [jwt-simple](https://npm.io/package/jwt-simple.md) — 259.5K weekly downloads
- [@exodus/patch-broken-hermes-typed-arrays](https://npm.io/package/@exodus/patch-broken-hermes-typed-arrays.md) — 28.5K weekly downloads
- [@native-to-anchor/buffer-layout](https://npm.io/package/@native-to-anchor/buffer-layout.md) — 12.2K weekly downloads
- [binary-parser-encoder](https://npm.io/package/binary-parser-encoder.md) — 5.3K weekly downloads

## Recent versions

- 0.2.0 (latest) — 2018-02-11
- 0.1.2 — 2018-02-08

## README

co-job
======
Run jobs in limited runners. Jobs can dynamicly be pushed in current runner

[![Build Status](https://travis-ci.org/orangemi/co-job.svg?branch=master)](https://travis-ci.org/orangemi/co-job)

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

## Quick start
```js
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
- [co](https://github.com/tj/co)

## 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<result>
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.

---
_Source: https://npm.io/package/co-job · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
