-
-
Save dfellis/6928436 to your computer and use it in GitHub Desktop.
namespaced queues working properly again in 0.6.20 and 0.7.8
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 localQ = q.ns(); | |
var items = []; | |
localQ('end') | |
.each(function() { | |
callback(items); | |
console.log('end'); | |
}); | |
localQ('recurse') | |
.each(function(data) { | |
data.Flag++; | |
items = items.concat(data.Items); | |
console.log('recurse - each items:', items); | |
return data; | |
}) | |
.branch(function(data) { | |
console.log('branching'); | |
return data.Flag > 1 ? 'end' : 'recurse'; | |
}); | |
localQ([data]).branch('recurse'); | |
} | |
scanAll({ | |
Items: ['X', 'firstScan-1', 'firstScan-2', 'firstScan-3'], | |
Flag: 0 | |
}, function(result) { | |
console.log('first result:', result); | |
}); | |
scanAll({ | |
Items: ['secondScan-1', 'secondScan-2', 'secondScan-3'], | |
Flag: 1 | |
}, 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