Comparing version 0.1.7 to 0.1.8
@@ -18,36 +18,25 @@ var async = require('async'); | ||
function moveQueueTask(node, callback) { | ||
try { | ||
moves(depth, node, function(err, newNodes) { | ||
if (err) return callback(err); | ||
if (foundGoal || !newNodes || !newNodes.length) | ||
return callback(); | ||
var goalQueue = async.queue(goalQueueTask, goal.parallel || 4); | ||
goalQueue.drain = callback; | ||
newNodes.forEach(function(newNode) { | ||
if (visited.hasOwnProperty(newNode)) return; | ||
nodeQueue.push(newNode); | ||
moves(depth, node, function(err, newNodes) { | ||
if (err) return callback(err); | ||
if (foundGoal || !newNodes || !newNodes.length) | ||
return callback(); | ||
var goalQueue = async.queue(goalQueueTask, goal.parallel || 4); | ||
goalQueue.drain = callback; | ||
newNodes.forEach(function(newNode) { | ||
if (visited.hasOwnProperty(newNode)) return; | ||
nodeQueue.push(newNode); | ||
visited[newNode] = {from: node}; | ||
goalQueue.push([newNode]); | ||
}); | ||
if (!goalQueue.length()) return callback(); | ||
function goalQueueTask(newNode, goalCallback) { | ||
if (foundGoal) return goalCallback(); | ||
goal(newNode, function(err, isGoal) { | ||
visited[newNode] = {from: node}; | ||
goalQueue.push([newNode]); | ||
if (err) return goalCallback(err); | ||
if (isGoal) foundGoal = {node: newNode}; | ||
goalCallback(); | ||
}); | ||
if (!goalQueue.length()) return callback(); | ||
function goalQueueTask(newNode, goalCallback) { | ||
if (foundGoal) return goalCallback(); | ||
goal(newNode, function(err, isGoal) { | ||
visited[newNode] = {from: node}; | ||
if (err) return goalCallback(err); | ||
if (isGoal) foundGoal = {node: newNode}; | ||
goalCallback(); | ||
}); | ||
}; | ||
}); | ||
} catch (e) { | ||
// In large graphs you may get a Maximum call stack size | ||
// exceeded error. Its best to reply with an error instead | ||
// of dying | ||
try { | ||
return callback(e); | ||
} catch (e) { | ||
// callback was already called. | ||
} | ||
} | ||
}; | ||
}); | ||
} | ||
@@ -54,0 +43,0 @@ function moveQueueDone() { |
{ | ||
"name": "async-bfs", | ||
"version": "0.1.7", | ||
"version": "0.1.8", | ||
"description": "Flexible functional async breadth first search", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
4797
92