Socket
Socket
Sign inDemoInstall

callback-sequence

Package Overview
Dependencies
5
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 3.0.0 to 3.1.0

10

changelog.md

@@ -1,3 +0,11 @@

<!-- a5016b8 1449485237000 -->
<!-- df9c29a 1449647658000 -->
## [v3.1.0](https://github.com/zoubin/callback-sequence/commit/df9c29a) (2015-12-09)
* [[`30a2f05`](https://github.com/zoubin/callback-sequence/commit/30a2f05)] Support custom runner
* [[`a286a0e`](https://github.com/zoubin/callback-sequence/commit/a286a0e)] Add coverage badge
* [[`1cc8e5c`](https://github.com/zoubin/callback-sequence/commit/1cc8e5c)] CHANGELOG
## [v3.0.0](https://github.com/zoubin/callback-sequence/commit/a5016b8) (2015-12-07)

@@ -4,0 +12,0 @@

44

lib/runner.js

@@ -12,24 +12,44 @@ var runCallback = require('run-callback')

this.output = opts.output !== false
if (typeof opts.run === 'function') {
this._run = opts.run
} else {
this._runner = runCallback.Runner(opts.run)
}
}
Runner.prototype.normalizeArgs = function(args) {
return this.input && defined(args) ? args : []
if (!this.input || !defined(args)) return []
return Array.isArray(args) ? args : [args]
}
Runner.prototype.normalizeResult = function(res) {
return this.output ? res : []
}
Runner.prototype.run = function(cb, args) {
args = this.normalizeArgs(args)
return runCallback.apply(null, [cb].concat(args))
args = [cb].concat(args)
return Promise.resolve(this).then(function (runner) {
return runner._run.apply(runner, args)
})
}
Runner.prototype._run = function(cb) {
return this._runner.thunkify(cb)
.apply(this._runner, slice(arguments, 1))
}
Runner.prototype.sequence = function(cbs, args, i) {
if (!Array.isArray(cbs)) cbs = [cbs]
args = this.normalizeArgs(args)
i = ~~i
var cb = cbs[i]
// NOTE: tasks can be pushed to `cbs` dynamically
var cb = cbs[i]
// **NOTE**: tasks can be pushed to `cbs` dynamically
if (i < cbs.length) ++i
var ret
if (typeof cb === 'function') {
++i
ret = this.run(cb, args)
} else if (Array.isArray(cb)) {
++i
ret = this.parallel(cb, args)

@@ -45,3 +65,3 @@ } else {

}
if (self.output) return res
return self.normalizeResult(res)
})

@@ -51,3 +71,5 @@ }

Runner.prototype.parallel = function(cbs, args) {
var self = this
if (!Array.isArray(cbs)) cbs = [cbs]
args = this.normalizeArgs(args)
return Promise.all(cbs.map(function (cb) {

@@ -62,5 +84,3 @@ if (typeof cb === 'function') {

}, this))
.then(function (res) {
if (self.output) return res
})
.then(this.normalizeResult.bind(this))
}

@@ -67,0 +87,0 @@

{
"name": "callback-sequence",
"version": "3.0.0",
"version": "3.1.0",
"description": "Make a new callback to run input callbacks in sequence",

@@ -29,3 +29,3 @@ "main": "index.js",

"dependencies": {
"run-callback": "^3.0.0"
"run-callback": "^3.1.0"
},

@@ -32,0 +32,0 @@ "devDependencies": {

# callback-sequence
[![version](https://img.shields.io/npm/v/callback-sequence.svg)](https://www.npmjs.org/package/callback-sequence)
[![status](https://travis-ci.org/zoubin/callback-sequence.svg?branch=master)](https://travis-ci.org/zoubin/callback-sequence)
[![coverage](https://img.shields.io/coveralls/zoubin/callback-sequence.svg)](https://coveralls.io/github/zoubin/callback-sequence)
[![dependencies](https://david-dm.org/zoubin/callback-sequence.svg)](https://david-dm.org/zoubin/callback-sequence)

@@ -244,3 +245,17 @@ [![devDependencies](https://david-dm.org/zoubin/callback-sequence/dev-status.svg)](https://david-dm.org/zoubin/callback-sequence#info=devDependencies)

##### run
Specify a runner function to run each callback.
Type: `Function`, `Object`
Default: `null`
If `Function`, it receives a callback followed by a list of arguments,
and should return a promise to fetch the results (`Array`).
If `Object`, it is passed to
[`Runner of run-callback`](https://github.com/zoubin/run-callback#runner--runrunner)
to create a runner function.
## [Changelog](changelog.md)
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc