Skip to content

Instantly share code, notes, and snippets.

@ruidlopes
Created April 19, 2011 15:38
Show Gist options
  • Save ruidlopes/928494 to your computer and use it in GitHub Desktop.
Save ruidlopes/928494 to your computer and use it in GitHub Desktop.
an event-based approach to github.com/bpedro/node-expectation
exports.create = function(checkFunction, data, period) {
var emitter = new (require("events").EventEmitter)();
var wrapper = function(data) {
if (result = checkFunction(data))
emitter.emit("checked", result);
else
setTimeout(emitter.start, period || 1000);
};
emitter.start = function () { emitter.emit("start"); };
emitter.on("start", function() { wrapper(data); });
return emitter;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment