Skip to content

Instantly share code, notes, and snippets.

@dfellis
Forked from gmp/gist:6927324
Last active December 25, 2015 05:49
Show Gist options
  • Save dfellis/6927599 to your computer and use it in GitHub Desktop.
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
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