Comparing version 2.0.0 to 2.1.0
2.1.0 / 2013-10-21 | ||
================== | ||
* add passing of arguments into the generator. closes #33. | ||
2.0.0 / 2013-10-14 | ||
@@ -3,0 +8,0 @@ ================== |
13
index.js
@@ -6,2 +6,3 @@ /** | ||
var toString = Object.prototype.toString; | ||
var slice = Array.prototype.slice; | ||
@@ -24,5 +25,5 @@ /** | ||
function co(fn) { | ||
var gen = isGenerator(fn) ? fn : fn.call(this); | ||
var ctx = this; | ||
var done; | ||
var gen; | ||
@@ -34,3 +35,3 @@ function next(err, res) { | ||
if (arguments.length > 2) { | ||
res = [].slice.call(arguments, 1); | ||
res = slice.call(arguments, 1); | ||
} | ||
@@ -83,4 +84,6 @@ | ||
return function(fn){ | ||
done = fn; | ||
return function(){ | ||
var args = slice.call(arguments); | ||
done = args.pop(); | ||
gen = isGenerator(fn) ? fn : fn.apply(ctx, args); | ||
next(); | ||
@@ -99,3 +102,3 @@ } | ||
exports.join = function(fns) { | ||
if (!Array.isArray(fns)) fns = [].slice.call(arguments); | ||
if (!Array.isArray(fns)) fns = slice.call(arguments); | ||
var ctx = this; | ||
@@ -102,0 +105,0 @@ |
{ | ||
"name": "co", | ||
"version": "2.0.0", | ||
"version": "2.1.0", | ||
"description": "generator async flow control goodness", | ||
@@ -18,3 +18,3 @@ "keywords": [ | ||
"request": "~2.27.0", | ||
"matcha": "visionmedia/matcha" | ||
"matcha": "~0.4.0" | ||
}, | ||
@@ -21,0 +21,0 @@ "license": "MIT", |
@@ -11,4 +11,4 @@ # Co | ||
Co is careful to relay any errors that occur back to the generator, including those | ||
within the thunk, or from the thunk's callback. "Uncaught" exceptions in the generator are | ||
then either passed `co()`'s thunk or thrown. | ||
within the thunk, or from the thunk's callback. "Uncaught" exceptions in the generator | ||
are passed to `co()`'s thunk. | ||
@@ -25,3 +25,3 @@ Make sure to view the [examples](https://github.com/visionmedia/co/tree/master/examples). | ||
View the [wiki](https://github.com/visionmedia/co/wiki) for libraries that | ||
View the [wiki](https://github.com/visionmedia/co/wiki) for libraries that | ||
work well with Co. | ||
@@ -178,3 +178,3 @@ | ||
console.log(b); | ||
}); | ||
})() | ||
``` | ||
@@ -209,3 +209,3 @@ | ||
If a thunk is written to execute immediately you may acheive parallelism | ||
If a thunk is written to execute immediately you may acheive parallelism | ||
by simply `yield`-ing _after_ the call. The following are equivalent since | ||
@@ -236,2 +236,13 @@ each call kicks off execution immediately: | ||
You can also pass arguments into the generator. The last argument, `done`, is | ||
the callback function. Here's an example: | ||
```js | ||
var exec = require('co-exec'); | ||
co(function *(cmd) { | ||
var res = yield exec(cmd); | ||
return res; | ||
})('pwd', done); | ||
``` | ||
### co.join(fn...) | ||
@@ -238,0 +249,0 @@ |
@@ -32,3 +32,18 @@ | ||
}) | ||
it('should pass arguments into generator', function(done) { | ||
co(function *(a, b) { | ||
assert('yay' == a); | ||
assert('wahoo' == b); | ||
})('yay', 'wahoo', done); | ||
}); | ||
it('should pass arguments into generator with yields', function(done) { | ||
co(function *(a, b) { | ||
assert('yay' == a); | ||
yield work | ||
assert('wahoo' == b); | ||
})('yay', 'wahoo', 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
34184
997
315