Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

this adds finally as suggested in my ticket #20 #23

Open
wants to merge 2 commits into from

2 participants

@drauschenbach

I wish ".do()" was better documented. It looks like it's used as a finally in the unit tests:

Seq([1])
    .seq(function (n) {
        assert.eql(n, 1);
        calls.before = true;
        this('pow!');
        calls.after = true;
    })
    .seq(function (n) {
        calls.next = true;
        assert.fail('should have skipped this');
    })
    .catch(function (err) {
        assert.eql(err, 'pow!');
        assert.ok(calls.before);
        assert.ok(!calls.after);
        assert.ok(!calls.next);
        clearTimeout(to);
    })
    .do(function () {
        //assert.ok(calls.after);
        clearTimeout(tf);
    })
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Oct 20, 2011
  1. @FugueNation
Commits on Nov 24, 2011
  1. @FugueNation

    break new actions into a fresh stack, this gives a CPU time penalty, …

    FugueNation authored
    …but avoids stack overflows risks
This page is out of date. Refresh to see the latest.
Showing with 42 additions and 38 deletions.
  1. +42 −38 index.js
View
80 index.js
@@ -32,48 +32,50 @@ function builder (saw, xs) {
context.stack_ = context.stack;
function action (step, key, f, g) {
- var cb = function (err) {
- var args = [].slice.call(arguments, 1);
- if (err) {
- context.error = { message : err, key : key };
- saw.jump(lastPar);
- saw.down('catch');
- g();
- }
- else {
- if (typeof key == 'number') {
- context.stack_[key] = args[0];
- context.args[key] = args;
+ process.nextTick(function() {
+ var cb = function (err) {
+ var args = [].slice.call(arguments, 1);
+ if (err) {
+ context.error = { message : err, key : key };
+ saw.jump(lastPar);
+ saw.down('catch');
+ g();
}
else {
- context.stack_.push.apply(context.stack_, args);
- if (key !== undefined) {
- context.vars[key] = args[0];
+ if (typeof key == 'number') {
+ context.stack_[key] = args[0];
context.args[key] = args;
}
+ else {
+ context.stack_.push.apply(context.stack_, args);
+ if (key !== undefined) {
+ context.vars[key] = args[0];
+ context.args[key] = args;
+ }
+ }
+ if (g) g(args, key);
}
- if (g) g(args, key);
- }
- };
- Hash(context).forEach(function (v,k) { cb[k] = v });
-
- cb.into = function (k) {
- key = k;
- return cb;
- };
-
- cb.next = function (err, xs) {
- context.stack_.push.apply(context.stack_, xs);
- cb.apply(cb, [err].concat(context.stack));
- };
-
- cb.pass = function (err) {
- cb.apply(cb, [err].concat(context.stack));
- };
-
- cb.ok = cb.bind(cb, null);
-
- f.apply(cb, context.stack);
+ };
+ Hash(context).forEach(function (v,k) { cb[k] = v });
+
+ cb.into = function (k) {
+ key = k;
+ return cb;
+ };
+
+ cb.next = function (err, xs) {
+ context.stack_.push.apply(context.stack_, xs);
+ cb.apply(cb, [err].concat(context.stack));
+ };
+
+ cb.pass = function (err) {
+ cb.apply(cb, [err].concat(context.stack));
+ };
+
+ cb.ok = cb.bind(cb, null);
+
+ f.apply(cb, context.stack);
+ });
}
var running = 0;
@@ -152,7 +154,9 @@ function builder (saw, xs) {
saw.next();
};
- [ 'seq', 'par' ].forEach(function (name) {
+ this['finally'] = this.seq;
+
+ [ 'seq', 'par', 'finally' ].forEach(function (name) {
this[name + '_'] = function (key) {
var args = [].slice.call(arguments);
Something went wrong with that request. Please try again.