Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/atlassubbed/atlas-serial
https://github.com/atlassubbed/atlas-serial
Last synced: 21 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/atlassubbed/atlas-serial
- Owner: atlassubbed
- License: other
- Created: 2018-07-14T03:25:08.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2018-07-14T05:42:16.000Z (over 6 years ago)
- Last Synced: 2024-11-05T18:15:02.271Z (2 months ago)
- Language: JavaScript
- Size: 10.7 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# atlas-serial
Run async functions in serial with an onDone callback.
[![Travis](https://img.shields.io/travis/atlassubbed/atlas-serial.svg)](https://travis-ci.org/atlassubbed/atlas-serial)
---
## install
```
npm install --save atlas-serial
```## why
This is for running async subroutines in serial, regardless of whether or not tasks up the chain return errors. Since this is purely for control flow, tasks' results aren't tracked at all. If your Nth task depends on your N-1th task's outcome, use [atlas-waterfall](https://github.com/atlassubbed/atlas-waterfall#readme) or some other structure.
## examples
Usage is pretty simple -- just pass in an array of jobs (which each take a `done` callback) and an `allDone` callback. The `allDone` callback is optional and is called after each of the `done` callbacks have been called.
#### array of jobs
The following will run `reddit.post` only *after* `email.send` has finished:
```javascript
const serial = require("atlas-serial");
serial([
done => email.send("[email protected]", "hello", err => {
done(err)
}),
done => reddit.post("atlassubbed.png", "mildlyinteresting", err => {
done(err);
})
], errs => {
// all done!
// errs === [] on success
// errs === [err2] if job2 fails
// errs === [err1, err2] if both fail
})
```## caveats
Since order is important, a hash of tasks is not supported, as object key order is not guaranteed in javascript. If you care about return values and which error is which, use [atlas-waterfall](https://github.com/atlassubbed/atlas-waterfall#readme) instead.