Skip to content

Commit

Permalink
Merge pull request #3 from markuplab/fix-sync-outputs
Browse files Browse the repository at this point in the history
Fix sync action outputs to async actions
  • Loading branch information
markuplab committed Dec 2, 2015
2 parents 9240ddb + ccf01f5 commit 53b10c7
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/appstate.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,9 @@ function runBranch (index, options) {
}

if (Array.isArray(currentBranch)) {
runAsyncBranch(index, currentBranch, options);
return runAsyncBranch(index, currentBranch, options);
} else {
runSyncBranch(index, currentBranch, options);
return runSyncBranch(index, currentBranch, options);
}
}

Expand Down Expand Up @@ -206,7 +206,7 @@ function runSyncBranch (index, currentBranch, options) {
});

if (runResult && runResult.then) {
return result.then(() => {
return runResult.then(() => {
return runBranch(index + 1, options);
});
}
Expand Down
34 changes: 34 additions & 0 deletions test/suites/appstate.js
Original file line number Diff line number Diff line change
Expand Up @@ -510,4 +510,38 @@ lab.experiment('#appstate', function () {
done();
});
});

lab.test('should correct run tree with sync action that output to async', (done) => {
var counter = 0;

function async (args, state, output) {
setTimeout(() => {
counter += 1;
assert.equal(counter, 1);
output.success();
}, 0);
}

function sync (args, state, output) {
output.success();
}

var signal = appstate.create('test', [
sync, {
success: [
[
async, {
success: [noop]
}
]
]
}
]);

signal(tree).then(function () {
counter += 1;
assert.equal(counter, 2);
done();
}).catch(done);
});
});

0 comments on commit 53b10c7

Please sign in to comment.