Permalink
Browse files

multiple runs with multiple actions passing in sync scenario

  • Loading branch information...
brianc committed Dec 21, 2010
1 parent ad17ec3 commit 75d22d29992f6d4c0f12ae84cf5beb4386b65a75
Showing with 24 additions and 9 deletions.
  1. +21 −7 lib/index.js
  2. +3 −2 test/initial-tests.js
View
@@ -1,19 +1,33 @@
+var executeAction = function(action, callback) {
+ var i = 0
+ var doAction = function(action) {
+ //no more repeats to execute
+ if(action.repeat > i++) {
+ action.run(function() {
+ doAction(action)
+ })
+ } else {
+ callback();
+ }
+ }
+ doAction(action)
+}
+
module.exports = {
bench: function(config) {
return function(callback) {
- var action = config.actions[0];
- var i = 0
+ var i = 0;
var doAction = function(action) {
- //no more repeats to execute
- if(config.repeat > i++) {
- action.run(function() {
- doAction(action)
+ if(action) {
+ action.repeat = config.repeat;
+ executeAction(action, function() {
+ doAction(config.actions[i++])
})
} else {
callback();
}
}
- doAction(action)
+ doAction(config.actions[i++]);
}
}
}
View
@@ -47,6 +47,7 @@ test('multiple actions', function() {
var twoCalled = 0
var threeCalled = 0
var benchmark = bencher.bench({
+ repeat: 3,
actions:[{
name: 'calling 1',
run: function(next) {
@@ -71,15 +72,15 @@ test('multiple actions', function() {
test('calls first', function() {
oneCalled.should.equal(3)
})
-
+
test('calls second', function() {
twoCalled.should.equal(3)
})
test('calls third', function() {
threeCalled.should.equal(3)
})
-
+
}))
})

0 comments on commit 75d22d2

Please sign in to comment.