Installations
npm install callback-sequence
Developer Guide
Typescript
No
Module System
CommonJS
Node Version
4.2.1
NPM Version
2.14.7
Score
68.5
Supply Chain
98
Quality
75
Maintenance
100
Vulnerability
100
License
Releases
Unable to fetch releases
Contributors
Unable to fetch Contributors
Languages
JavaScript (100%)
Love this project? Help keep it running — sponsor us today! 🚀
Developer
zoubin
Download Statistics
Total Downloads
92,071
Last Day
2
Last Week
5
Last Month
89
Last Year
1,821
GitHub Statistics
1 Stars
37 Commits
2 Watching
1 Branches
1 Contributors
Bundle Size
5.47 kB
Minified
1.88 kB
Minified + Gzipped
Package Meta Information
Latest Version
3.2.0
Package Id
callback-sequence@3.2.0
Size
3.77 kB
NPM Version
2.14.7
Node Version
4.2.1
Total Downloads
Cumulative downloads
Total Downloads
92,071
Last day
0%
2
Compared to previous day
Last week
-73.7%
5
Compared to previous week
Last month
-49.4%
89
Compared to previous month
Last year
-49.7%
1,821
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
Dependencies
1
callback-sequence
Make a new callback to run callbacks in sequence or parallel.
Callbacks can be made async like gulp tasks.
Example
1var thunkify = require('callback-sequence') 2 3var Readable = require('stream').Readable 4var gulp = require('gulp') 5 6gulp.task('sequence', thunkify( 7 sync, async, promise, stream 8)) 9 10gulp.task('parallel', thunkify( 11 [sync, async, promise, stream] 12)) 13 14gulp.task('parallel-nested', thunkify( 15 // `async` and `promise` will be run in parallel 16 sync, [async, promise], stream 17)) 18 19gulp.task('sequence-nested', thunkify( 20 // `async` and `promise` will be run in sequence 21 [sync, [async, promise], stream] 22)) 23 24function sync() { 25} 26 27function async(cb) { 28 process.nextTick(cb) 29} 30 31function promise() { 32 return Promise.resolve() 33} 34 35function stream() { 36 var s = Readable() 37 s.push(null) 38 return s 39} 40
API
1var Runner = require('./lib/runner') 2var runner = new Runner({ input: false, output: false }) 3 4exports = module.exports = runner.thunkify.bind(runner) 5exports.run = exports.sequence = runner.sequence.bind(runner) 6exports.parallel = runner.parallel.bind(runner) 7exports.series = runner.series.bind(runner) 8exports.Runner = Runner 9
Runner
var runner = Runner(opts)
Create a new runner instance.
opts
input
Specify whether to pass the results of the previous callback to the next as arguments.
Type: Boolean
Default: true
1var Runner = require('callback-sequence').Runner 2 3var runner = Runner({ input: true }) 4 5runner.thunkify( 6 function (a, b) { 7 // 3 8 return a + b 9 }, 10 function (sum, next) { 11 process.nextTick(function () { 12 // 6 13 next(null, sum * 2) 14 }) 15 }, 16 function (product) { 17 return Promise.resolve().then(function () { 18 // 7 19 return product + 1 20 }) 21 } 22)(1, 2) 23.then(function (res) { 24 // [7] 25 console.log(res) 26}) 27 28
output
Specify whether to deliver results.
Type: Boolean
Default: true
If false
, the final results will always be []
.
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
to create a runner function.
cb = Runner.prototype.thunkify(...tasks)
Return a callback to run the specified tasks in the appearance order.
1var runner = Runner() 2 3runner.thunkify( 4 function (res) { 5 return res + 1 6 }, 7 function (res) { 8 return Promise.resolve() 9 .then(function () { 10 return res + 1 11 }) 12 }, 13 function (res, next) { 14 process.nextTick(function () { 15 next(null, res - 1, res + 1) 16 }) 17 } 18)(1) 19.then(function (res) { 20 // [ 2, 4 ] 21 console.log(res) 22}) 23
Runner.prototype.sequence(tasks)
Run tasks
in sequence.
NOTE: directly nested array of tasks will be run with Runner.prototype.parallel
.
1var runner = Runner() 2 3runner.sequence([ 4 function () { console.log(1) }, 5 [ 6 function (cb) { 7 setTimeout(function() { 8 console.log(3) 9 cb() 10 }, 0) 11 }, 12 function () { 13 return new Promise(function (resolve) { 14 process.nextTick(function () { 15 console.log(2) 16 resolve() 17 }) 18 }) 19 }, 20 ], 21 function () { console.log(4) }, 22]).then(function () { 23 console.log('DONE') 24}) 25 26// 1 27// 2 28// 3 29// 4 30// DONE 31
Callbacks can be added dynamically:
1var runner = Runner() 2 3var count = 5 4var tasks = [] 5 6var res = [] 7function task(next) { 8 process.nextTick(function () { 9 res.push(count) 10 if (--count > 0) { 11 tasks.push(task) 12 } 13 next() 14 }) 15} 16runner.sequence(tasks).then(function () { 17 // [5, 4, 3, 2, 1] 18 console.log(res) 19}) 20 21tasks.push(task) 22
Runner.prototype.parallel(tasks)
Run the specified tasks in parallel.
NOTE: directly nested array of tasks will be run with Runner.prototype.sequence
.
1var runner = Runner() 2 3var res = [] 4runner.parallel([ 5 function () { res.push(1) }, 6 [ 7 function () { 8 return Promise.resolve().then(function () { 9 res.push(4) 10 }) 11 }, 12 function () { res.push(5) }, 13 ], 14 function (cb) { 15 setTimeout(function() { 16 res.push(3) 17 cb() 18 }, 0) 19 }, 20 function (cb) { 21 res.push(2) 22 cb() 23 }, 24]) 25.then(function () { 26 // [1, 2, 4, 5, 3] 27 console.log(res) 28}) 29
Runner.prototype.series(...tasks)
Run tasks
in sequence.
However, while the results of sequence
is that of the last task,
the results of series
is an array containing all results of the tasks.
In addition, the results of the previous task will not be passed to the next as arguments.
NOTE: each element will be passed to Runner.prototype.sequence
.
1var runner = Runner() 2 3runner.series( 4 function () { 5 console.log(1) 6 return 1 7 }, 8 [ 9 function () { 10 return Promise.resolve().then(function () { 11 console.log(4) 12 return 4 13 }) 14 }, 15 function (cb) { 16 setTimeout(function() { 17 console.log(3) 18 cb(null, 3) 19 }, 0) 20 }, 21 function () { 22 console.log(5) 23 return 5 24 }, 25 ], 26 function (cb) { 27 console.log(2) 28 cb(null, 2) 29 } 30) 31.then(function (res) { 32 // 1 33 // 5 34 // 4 35 // 3 36 // 2 37 // [ [ 1 ], [ [ 4 ], [ 3 ], [ 5 ] ], [ 2 ] ] 38 console.log(res) 39}) 40
Changelog
![Empty State](/_next/static/media/empty.e5fae2e5.png)
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
0 existing vulnerabilities detected
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
Found 0/30 approved changesets -- score normalized to 0
Reason
no SAST tool detected
Details
- Warn: no pull requests merged into dev branch
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
- Warn: no security policy file detected
- Warn: no security file to analyze
- Warn: no security file to analyze
- Warn: no security file to analyze
Reason
project is not fuzzed
Details
- Warn: no fuzzer integrations found
Reason
license file not detected
Details
- Warn: project does not have a license file
Reason
branch protection not enabled on development/release branches
Details
- Warn: branch protection not enabled for branch 'master'
Score
2.6
/10
Last Scanned on 2025-01-27
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn MoreOther packages similar to callback-sequence
algoframe
A TypeScript comprehensive and modulated libary for doing algebraic animation with requestAnimatioFrame natively, even with Bezier and Sequences
after-sequence
Run several async functions and run a callback when they are gone.
callback-chain
A tool collecting callbacks and invoking them on demand in a sequence, passing a set of user provided arguments. It implements the linked list without using any data structure, but rather keeps provided callbacks in the correct order using the javascript
iterified
Convert any callback-based sequence of values into a full-fledged async iterable