Permalink
Browse files

implement suspend.fn()

  • Loading branch information...
1 parent f0471e2 commit a7b9a77d4c75f12053bba32b7d57b09dce403fb9 @jmar777 committed Dec 2, 2013
Showing with 12 additions and 0 deletions.
  1. +12 −0 lib/suspend.js
View
@@ -20,6 +20,18 @@ var suspend = module.exports = function async(generator) {
suspend.async = suspend;
+suspend.fn = function fn(generator) {
+ if (!isGeneratorFunction(generator)) {
+ throw new Error('First .fn() argument must be a GeneratorFunction.');
+ }
+
+ return function() {
+ var suspender = new Suspender(generator);
+ // preserve `this` context
+ suspender.start(this, Array.prototype.slice.call(arguments));
+ };
+};
+
suspend.run = function run(generator, callback) {
if (!isGeneratorFunction(generator)) {
throw new Error('First .run() argument must be a GeneratorFunction.');

0 comments on commit a7b9a77

Please sign in to comment.