Skip to content

Commit

Permalink
Implement callbacked break up.
Browse files Browse the repository at this point in the history
Closes #197.
  • Loading branch information
flatheadmill committed Feb 26, 2014
1 parent 92d1ef8 commit 38aaaf6
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 31 deletions.
16 changes: 3 additions & 13 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,18 +103,7 @@ function cadence () {

if (vargs[0] != null) {
if (vargs[0].invoke === invoke) {
var iterator = frame
var label = vargs.shift()
while (iterator.args) {
if (iterator.args[0].steps[0] === label.step) {
iterator.args[1] = 1
iterator.args[2].callbacks = frame.callbacks
if (!vargs.length) return true
return createHandler(frame, false, vargs)
}
iterator.args[1] = iterator.args[0].steps.length
iterator = iterator.caller
}
frame.callbacks[0].results[0].push(vargs.shift())
}

if (vargs[0] === -1) {
Expand Down Expand Up @@ -431,6 +420,7 @@ function cadence () {
frames[0].args = [ cadence, index + 1, frames[0], denouement ]

hold = step()
var results = frames[0].callbacks[0].results[0] = [ null, invoke ]
try {
result = cadence.steps[index].apply(this, vargs)
} catch (errors) {
Expand All @@ -446,7 +436,7 @@ function cadence () {
frames[0].called = frames[0].count - 1
}
frames.shift()
hold.apply(this, [ null, invoke ].concat(result === void(0) ? vargs : [ result ]))
hold.apply(this, results.concat([ result === void(0) ? vargs : result ]))
}

return execute
Expand Down
1 change: 1 addition & 0 deletions release.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
### Issue by Issue

* Implement callbacked break up. #197.
* Implement break up. #196.
* Remove `Label` class. #195.
* Implement jump out. #194.
Expand Down
21 changes: 3 additions & 18 deletions t/cadence/loop.t.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env node

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

Expand Down Expand Up @@ -114,27 +114,12 @@ require('proof')(21, function (step, equal, deepEqual) {

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 () {
step()(null, true)
step(retry)
}])(1)
})(function (error, result) {
if (error) throw error
equal(result, 10, 'loop continue')
})

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

0 comments on commit 38aaaf6

Please sign in to comment.