Skip to content

Instantly share code, notes, and snippets.

@scripting
Last active January 14, 2018 16:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save scripting/6236ae821789e5f89b6d6e724322c546 to your computer and use it in GitHub Desktop.
Save scripting/6236ae821789e5f89b6d6e724322c546 to your computer and use it in GitHub Desktop.
Code that manages queues for River5, for review. See the blog post linked to in the first comment. (Revision to earlier gist.)
function readRiverFile (relpath, afterReadCallback, callback) {
var f = config.dataFolder + relpath;
if (riverQueues [f] === undefined) {
riverQueues [f] = [callback];
fs.readFile (f, function (err, jsontext) {
var jstruct = undefined;
if (!err) {
try {
jstruct = JSON.parse (jsontext);
}
catch (err) {
}
}
jstruct = afterReadCallback (jstruct);
var theQueue = riverQueues [f];
delete riverQueues [f];
for (var i = 0; i < theQueue.length; i++) {
theQueue [i] (jstruct);
}
});
}
else {
riverQueues [f].push (callback);
}
}
@scripting
Copy link
Author

Here's the blog post that explains --

http://scripting.com/2018/01/14/155244.html

Dave

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment