Skip to content

Commit

Permalink
Implement break up.
Browse files Browse the repository at this point in the history
Closes #196.
  • Loading branch information
flatheadmill committed Feb 26, 2014
1 parent 99d66dc commit 92d1ef8
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 5 deletions.
14 changes: 10 additions & 4 deletions index.js
Expand Up @@ -233,11 +233,16 @@ function cadence () {
createCallback(frame, callback, 0).apply(null, [null].concat(vargs))
}

return {
invoke: invoke,
step: callback.steps[0],
offset: callback.steps.length
var label = function () {
label.offset = 0
return label
}

label.invoke = invoke
label.step = callback.steps[0]
label.offset = callback.steps.length

return label
}
}

Expand Down Expand Up @@ -353,6 +358,7 @@ function cadence () {
if (iterator.args[0].steps[0] === label.step) {
iterator.args[1] = label.offset
iterator.args[2].callbacks = previous.callbacks
iterator.args[2].errors.length = 0
return invoke.apply(this, iterator.args)
}
iterator.args[1] = iterator.args[0].steps.length
Expand Down
1 change: 1 addition & 0 deletions release.md
@@ -1,5 +1,6 @@
### Issue by Issue

* Implement break up. #196.
* Remove `Label` class. #195.
* Implement jump out. #194.
* Variable arguments last to counted or each loops. #193.
16 changes: 15 additions & 1 deletion t/cadence/loop.t.js
@@ -1,6 +1,6 @@
#!/usr/bin/env node

require('proof')(20, function (step, equal, deepEqual) {
require('proof')(21, function (step, equal, deepEqual) {
var fs = require('fs')
var cadence = require('../..')

Expand Down Expand Up @@ -141,6 +141,20 @@ require('proof')(20, function (step, equal, deepEqual) {
equal(result, 10, 'loop continue callbacked')
})

cadence(function (step) {
var count = 0
var retry = step([function (_, retry) {
if (retry) count++
if (count != 10) throw new Error
else step(null, 10)
}, function () {
return [ retry(), true ]
}])(1)
})(function (error, result) {
if (error) throw error
equal(result, 10, 'loop continue return')
})

cadence(function (step) {
var count = 0
var outer = step(function () {
Expand Down

0 comments on commit 92d1ef8

Please sign in to comment.