Comparing version 1.2.0 to 1.2.1
18
index.js
var acomb = exports; | ||
var _slice = [].slice; | ||
var _nextTick = setImmediate; | ||
var _nextTick; | ||
if (typeof setImmediate !== "undefined") { | ||
_nextTick = setImmediate; | ||
} | ||
if (!_nextTick) { // browsers | ||
@@ -105,6 +109,10 @@ _nextTick = function (fn) { | ||
var result; | ||
try { | ||
result = predicate.apply(this, args); | ||
} catch (e) { | ||
return callback(e); | ||
if (predicate === true || predicate === false) { | ||
result = predicate; | ||
} else { | ||
try { | ||
result = predicate.apply(this, args); | ||
} catch (e) { | ||
return callback(e); | ||
} | ||
} | ||
@@ -111,0 +119,0 @@ if (result) { |
{ | ||
"name": "acomb", | ||
"version": "1.2.0", | ||
"version": "1.2.1", | ||
"description": "Higher-order utilities for use with async functions", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -89,3 +89,3 @@ # acomb [![Build Status via Travis CI](https://travis-ci.org/aearly/acomb.svg)](https://travis-ci.org/aearly/acomb) [![NPM version](http://img.shields.io/npm/v/acomb.svg)](https://www.npmjs.org/package/acomb) | ||
Takes a function of the form `function(object, callback) {}` and converts it to the form `function(option1, option2, ... callback) {}` based on the strings passed. The strings passed will pick properties from the object and turn them in to direct arguments. Useful in `async.auto` in conjunction with `flip` for destructuring the results. | ||
Takes a function of the form `function(object, callback) {}` and converts it to the form `function(option1, option2, ... callback) {}` based on the strings passed. The strings passed will pick properties from the object and turn them in to direct arguments. Useful in `async.auto` in conjunction with `flip` for destructuring the results. You can also pass an array of strings as the second arg. | ||
@@ -154,2 +154,12 @@ ```js | ||
You can also pass a boolean directly as the first arg. | ||
```js | ||
async.waterfall([ | ||
func1, | ||
func2 | ||
async.provided(NODE_ENV === "dev", func3) | ||
], done); | ||
``` | ||
<a name="ensureAsync"> | ||
@@ -156,0 +166,0 @@ ### ensureAsync(func) |
63
test.js
@@ -187,35 +187,48 @@ var a = require("./"); | ||
}); | ||
}); | ||
describe("ensureAsync", function () { | ||
it("should defer if a sync function is passed", function (done) { | ||
var sameStack = true; | ||
it("should also work with a boolean", function (done) { | ||
var f = a.provided(true, function (x, y, cb) { | ||
assert(x === 1); | ||
assert(y === 2); | ||
assert(typeof cb === "function"); | ||
done(); | ||
}); | ||
a.ensureAsync(function (cb) { | ||
cb(); | ||
})(function () { | ||
assert(!sameStack); | ||
done(); | ||
}); | ||
f(1, 2, noop); | ||
}); | ||
}); | ||
sameStack = false; | ||
describe("ensureAsync", function () { | ||
it("should defer if a sync function is passed", function (done) { | ||
var sameStack = true; | ||
a.ensureAsync(function (cb) { | ||
cb(); | ||
})(function () { | ||
assert(!sameStack); | ||
done(); | ||
}); | ||
it("should not defer async functions", function (done) { | ||
var sameStack; | ||
a.ensureAsync(function (arg, cb) { | ||
assert(arg === 234); | ||
setTimeout(function () { | ||
sameStack = true; | ||
cb(123, 456); | ||
sameStack = false; | ||
}, 0); | ||
})(234, function (err, result) { | ||
assert(err === 123); | ||
assert(result === 456); | ||
assert(sameStack); | ||
done(); | ||
}); | ||
sameStack = false; | ||
}); | ||
it("should not defer async functions", function (done) { | ||
var sameStack; | ||
a.ensureAsync(function (arg, cb) { | ||
assert(arg === 234); | ||
setTimeout(function () { | ||
sameStack = true; | ||
cb(123, 456); | ||
sameStack = false; | ||
}, 0); | ||
})(234, function (err, result) { | ||
assert(err === 123); | ||
assert(result === 456); | ||
assert(sameStack); | ||
done(); | ||
}); | ||
}); | ||
}); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
16967
354
184