[Pkg-javascript-commits] [node-nextback] 01/03: Imported Upstream version 0.1.0

Sebastiaan Couwenberg sebastic at moszumanska.debian.org
Sat Mar 21 16:27:50 UTC 2015


This is an automated email from the git hooks/post-receive script.

sebastic pushed a commit to branch master
in repository node-nextback.

commit 12065dc460640686bd421b22bb4bce282cbe28af
Author: Bas Couwenberg <sebastic at xs4all.nl>
Date:   Sat Mar 21 16:49:15 2015 +0100

    Imported Upstream version 0.1.0
---
 .npmignore   |  6 +++++
 .travis.yml  |  7 ++++++
 LICENSE      | 20 ++++++++++++++++
 README.md    | 78 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 index.js     | 11 +++++++++
 package.json | 25 +++++++++++++++++++
 test/main.js | 60 ++++++++++++++++++++++++++++++++++++++++++++++
 7 files changed, 207 insertions(+)

diff --git a/.npmignore b/.npmignore
new file mode 100644
index 0000000..b5ef13a
--- /dev/null
+++ b/.npmignore
@@ -0,0 +1,6 @@
+.DS_Store
+*.log
+node_modules
+build
+*.node
+components
\ No newline at end of file
diff --git a/.travis.yml b/.travis.yml
new file mode 100644
index 0000000..37a228c
--- /dev/null
+++ b/.travis.yml
@@ -0,0 +1,7 @@
+language: node_js
+node_js:
+  - "0.6"
+  - "0.7"
+  - "0.8"
+  - "0.9"
+  - "0.10"
\ No newline at end of file
diff --git a/LICENSE b/LICENSE
new file mode 100755
index 0000000..4f482f9
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1,20 @@
+Copyright (c) 2013 Fractal <contact at wearefractal.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.
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..f71426c
--- /dev/null
+++ b/README.md
@@ -0,0 +1,78 @@
+[![Build Status](https://travis-ci.org/wearefractal/nextback.png?branch=master)](https://travis-ci.org/wearefractal/nextback)
+
+[![NPM version](https://badge.fury.io/js/nextback.png)](http://badge.fury.io/js/nextback)
+
+## Information
+
+<table>
+<tr> 
+<td>Package</td><td>nextback</td>
+</tr>
+<tr>
+<td>Description</td>
+<td>Wraps callbacks in async</td>
+</tr>
+<tr>
+<td>Node Version</td>
+<td>>= 0.4</td>
+</tr>
+</table>
+
+## What
+
+`nextback` makes sure your callbacks don't return immediately by wrapping them in a setImmediate or nextTick.
+
+## What you shouldn't do
+
+```javascript
+var doAsync = function(cb) {
+  if (somethingIsWrong) {
+    return cb(new Error("Crap"));
+  }
+  doWork(function(data){
+    cb(null, data);
+  });
+};
+```
+
+## What you should do
+
+```javascript
+var nextback = require('nextback');
+
+var doAsync = function(cb) {
+  cb = nextback(cb);
+
+  if (somethingIsWrong) {
+    return cb(new Error("Crap"));
+  }
+  doWork(function(data){
+    cb(null, data);
+  });
+};
+```
+
+## LICENSE
+
+(MIT License)
+
+Copyright (c) 2013 Fractal <contact at wearefractal.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.
diff --git a/index.js b/index.js
new file mode 100644
index 0000000..1647ecd
--- /dev/null
+++ b/index.js
@@ -0,0 +1,11 @@
+var tick = process.setImmediate || process.nextTick;
+
+module.exports = function(callback){
+  return function(){
+    var self = this;
+    var args = arguments;
+    tick(function(){
+      callback.apply(self, args);
+    });
+  };
+};
\ No newline at end of file
diff --git a/package.json b/package.json
new file mode 100644
index 0000000..ac5f30a
--- /dev/null
+++ b/package.json
@@ -0,0 +1,25 @@
+{
+  "name": "nextback",
+  "description": "Wraps callbacks in async",
+  "version": "0.1.0",
+  "homepage": "http://github.com/wearefractal/nextback",
+  "repository": "git://github.com/wearefractal/nextback.git",
+  "author": "Fractal <contact at wearefractal.com> (http://wearefractal.com/)",
+  "main": "./index.js",
+  "devDependencies": {
+    "mocha": "^1.18.2",
+    "should": "^3.2.0-beta1"
+  },
+  "scripts": {
+    "test": "mocha"
+  },
+  "engines": {
+    "node": ">= 0.4.0"
+  },
+  "licenses": [
+    {
+      "type": "MIT",
+      "url": "http://github.com/wearefractal/nextback/raw/master/LICENSE"
+    }
+  ]
+}
diff --git a/test/main.js b/test/main.js
new file mode 100644
index 0000000..f8701c2
--- /dev/null
+++ b/test/main.js
@@ -0,0 +1,60 @@
+var nextback = require('../');
+var should = require('should');
+require('mocha');
+
+describe('nextback', function() {
+  it('should pass arguments correctly', function(done) {
+    var fn = function(err, one, two) {
+      should.not.exist(err);
+      should.exist(one);
+      should.exist(two);
+      one.should.equal(1);
+      two.should.equal(2);
+      done();
+    };
+    nextback(fn)(null, 1, 2);
+  });
+
+  it('should run things in order', function(done) {
+    var ran = false;
+
+    var fn = function() {
+      ran = true;
+    };
+    ran.should.equal(false);
+    nextback(fn)();
+    ran.should.equal(false);
+    process.nextTick(function(){
+      ran.should.equal(true);
+      done();
+    });
+  });
+
+  it('should run things in order with mutating state', function(done) {
+    var o = {
+      name: "todd"
+    };
+
+    var fn = function() {
+      o.name.should.equal("jesse");
+      done();
+    };
+    nextback(fn)(o);
+    o.name = "jesse";
+  });
+
+  it('should run things with a given context', function(done) {
+    var ctx = {
+      hello: 'dude'
+    };
+
+    var fn = function(arg) {
+      this.hello.should.equal('dude');
+      arg.should.equal('dude');
+      done();
+    };
+
+    nextback(fn).apply(ctx, ['dude']);
+  });
+
+});

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/node-nextback.git



More information about the Pkg-javascript-commits mailing list