-
-
Save dfellis/6927599 to your computer and use it in GitHub Desktop.
locally scoping, but the result is an infinite loop for the second scanAll
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var q = require('queue-flow'); | |
function scanAll (data, callback) { | |
console.log('scanAll with data:', data); | |
var counter = 0; | |
var items = []; | |
var end = q(); | |
end | |
.each(function() { | |
console.log('end'); | |
callback(items); | |
}); | |
var recurse = q(); | |
recurse | |
.each(function(data) { | |
if (data.Items[0] === 'X') counter++; | |
items = items.concat(data.Items); | |
console.log('recurse - each items:', items); | |
}) | |
.branch(function() { | |
return counter > 1 ? end : recurse; | |
}); | |
q([data]).branch(recurse); | |
} | |
scanAll({ | |
Items: ['X', 'firstScan-1', 'firstScan-2', 'firstScan-3'] | |
}, function(result) { | |
console.log('first result:', result); | |
}); | |
scanAll({ | |
Items: ['secondScan-1', 'secondScan-2', 'secondScan-3'] | |
}, function(result) { | |
console.log('second result:', result); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment