[Pkg-javascript-commits] [node-array-series] 01/02: Imported Upstream version 0.1.5
Thorsten Alteholz
alteholz at moszumanska.debian.org
Thu Feb 4 20:41:43 UTC 2016
This is an automated email from the git hooks/post-receive script.
alteholz pushed a commit to branch master
in repository node-array-series.
commit 7834240a4b346972c9ba723763721b89d9ce3ebb
Author: Thorsten Alteholz <debian at alteholz.de>
Date: Thu Feb 4 21:41:35 2016 +0100
Imported Upstream version 0.1.5
---
.gitignore | 58 ++++++++++++++++++++++++++++++++++++++
.travis.yml | 4 +++
README.md | 76 ++++++++++++++++++++++++++++++++++++++++++++++++++
component.json | 11 ++++++++
index.js | 34 +++++++++++++++++++++++
package.json | 23 +++++++++++++++
test.js | 88 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
7 files changed, 294 insertions(+)
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..03622f0
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,58 @@
+# Compiled source #
+###################
+*.com
+*.class
+*.dll
+*.exe
+*.o
+*.so
+
+# Packages #
+############
+# it's better to unpack these files and commit the raw source
+# git has its own built in compression methods
+*.7z
+*.dmg
+*.gz
+*.iso
+*.jar
+*.rar
+*.tar
+*.zip
+
+# Logs and databases #
+######################
+*.log
+*.sql
+*.sqlite
+
+# OS generated files #
+######################
+.DS_Store*
+ehthumbs.db
+Icon?
+Thumbs.db
+
+# Node.js #
+###########
+lib-cov
+*.seed
+*.log
+*.csv
+*.dat
+*.out
+*.pid
+*.gz
+
+pids
+logs
+results
+
+node_modules
+npm-debug.log
+
+# Components #
+##############
+
+/build
+/components
\ No newline at end of file
diff --git a/.travis.yml b/.travis.yml
new file mode 100644
index 0000000..a12e3f0
--- /dev/null
+++ b/.travis.yml
@@ -0,0 +1,4 @@
+language: node_js
+node_js:
+ - "0.8"
+ - "0.10"
\ No newline at end of file
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..4a2e219
--- /dev/null
+++ b/README.md
@@ -0,0 +1,76 @@
+# Array Series [![Build Status](https://travis-ci.org/component/array-series.png)](https://travis-ci.org/component/array-series)
+
+Call an array of asynchronous functions in series
+
+### API
+
+#### series(fns[, context[, callback]])
+
+```js
+var series = require('array-series')
+
+series([
+ function (done) {
+ done()
+ }
+], this, function (err) {
+
+})
+```
+
+#### fns
+
+`fns` is an array of functions to call in series.
+The argument signature should be:
+
+```js
+function (done) {
+ done(new Error())
+ // or
+ done()
+}
+```
+
+That is, each function should only take a `done` as an argument.
+Each callback should only take an optional `Error` as an argument.
+
+#### context
+
+Optional context to pass to each `fn`.
+Basically `fn.call(context, done)`.
+
+#### callback(err)
+
+```js
+function (err) {
+
+}
+```
+
+Only argument is an `Error` argument.
+It will return the first error in the series of functions that returns an error,
+and no function after will be called.
+
+### License
+
+The MIT License (MIT)
+
+Copyright (c) 2013 Jonathan Ong me at jongleberry.com
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+THE SOFTWARE.
\ No newline at end of file
diff --git a/component.json b/component.json
new file mode 100644
index 0000000..e229772
--- /dev/null
+++ b/component.json
@@ -0,0 +1,11 @@
+{
+ "name": "array-series",
+ "description": "Call an array of asynchronous functions in series",
+ "repo": "component/array-series",
+ "version": "0.1.5",
+ "main": "index.js",
+ "scripts": [
+ "index.js"
+ ],
+ "license": "MIT"
+}
\ No newline at end of file
diff --git a/index.js b/index.js
new file mode 100644
index 0000000..778f8d1
--- /dev/null
+++ b/index.js
@@ -0,0 +1,34 @@
+module.exports = function series(fns, context, callback) {
+ if (!callback) {
+ if (typeof context === 'function') {
+ callback = context
+ context = null
+ } else {
+ callback = noop
+ }
+ }
+
+ if (!(fns && fns.length)) return callback();
+
+ fns = fns.slice(0)
+
+ var call = context
+ ? function () {
+ fns.length
+ ? fns.shift().call(context, next)
+ : callback()
+ }
+ : function () {
+ fns.length
+ ? fns.shift()(next)
+ : callback()
+ }
+
+ call()
+
+ function next(err) {
+ err ? callback(err) : call()
+ }
+}
+
+function noop() {}
diff --git a/package.json b/package.json
new file mode 100644
index 0000000..04cd513
--- /dev/null
+++ b/package.json
@@ -0,0 +1,23 @@
+{
+ "name": "array-series",
+ "description": "Call an array of asynchronous functions in series",
+ "version": "0.1.5",
+ "scripts": {
+ "test": "node test"
+ },
+ "author": {
+ "name": "Jonathan Ong",
+ "email": "me at jongleberry.com",
+ "url": "http://jongleberry.com",
+ "twitter": "https://twitter.com/jongleberry"
+ },
+ "repository": {
+ "type": "git",
+ "url": "https://github.com/component/array-series.git"
+ },
+ "bugs": {
+ "url": "https://github.com/component/array-series/issues",
+ "email": "me at jongleberry.com"
+ },
+ "license": "MIT"
+}
diff --git a/test.js b/test.js
new file mode 100644
index 0000000..9e9ec4e
--- /dev/null
+++ b/test.js
@@ -0,0 +1,88 @@
+var assert = require('assert')
+var series = require('./')
+
+var a, b, c
+
+series([
+ function (done) {
+ a = 1
+ process.nextTick(done)
+ check('a')
+ },
+ function (done) {
+ b = 2
+ process.nextTick(done)
+ check('b')
+ },
+ function (done) {
+ c = 3
+ process.nextTick(done)
+ check('c')
+ }
+], function (err) {
+ assert.ifError(err)
+ assert.equal(a, 1)
+ assert.equal(b, 2)
+ assert.equal(c, 3)
+})
+
+function check(x) {
+ switch (x) {
+ case 'a':
+ assert.equal(a, 1)
+ assert.equal(b, undefined)
+ assert.equal(c, undefined)
+ break
+ case 'b':
+ assert.equal(a, 1)
+ assert.equal(b, 2)
+ assert.equal(c, undefined)
+ break
+ case 'c':
+ assert.equal(a, 1)
+ assert.equal(b, 2)
+ assert.equal(c, 3)
+ break
+ }
+}
+
+var context = 'hello'
+series([function (done) {
+ assert.equal(this, context)
+ done()
+}], context)
+
+var finished
+series([], function (err) {
+ finished = true
+})
+
+process.nextTick(function () {
+ if (!finished)
+ throw new Error('Failed with no functions.');
+})
+
+var r, d, o
+series([
+ function (done) {
+ r = 1
+ process.nextTick(done)
+ },
+ function (done) {
+ d = 0
+ process.nextTick(function () {
+ done(new Error('message'))
+ })
+ },
+ function (done) {
+ o = 0
+ process.nextTick(done)
+ }
+], function (err) {
+ assert.equal(err.message, 'message')
+ assert.equal(r, 1)
+ assert.equal(d, 0)
+ assert.equal(o, undefined)
+})
+
+console.log('Array series tests pass!')
\ No newline at end of file
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/node-array-series.git
More information about the Pkg-javascript-commits
mailing list