Skip to content

Instantly share code, notes, and snippets.

@mafintosh
Created April 10, 2018 22:16
Show Gist options
  • Save mafintosh/08c29ff876f0444b7270cf8335cbf650 to your computer and use it in GitHub Desktop.
Save mafintosh/08c29ff876f0444b7270cf8335cbf650 to your computer and use it in GitHub Desktop.
function iterate (db, onnode, done) {
visit(db, [], onnode, cb)
}
function visit (db, path, onnode, cb) {
var val = 0
loop(null)
function loop (err) {
if (err) return cb(err)
if (val > 4) return cb(null)
var next = path.concat(val++)
db.get('', {path: next, prefix: true}, function (err, nodes) {
if (err) return cb(err)
for (var i = 0; i < nodes.length; i++) {
var node = nodes[i]
if (node.path.join('') === next.join('')) onnode(node)
}
if (!nodes.length) return loop(null)
visit(db, next, onnode, loop)
})
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment