Created
April 19, 2011 15:38
-
-
Save ruidlopes/928494 to your computer and use it in GitHub Desktop.
an event-based approach to github.com/bpedro/node-expectation
This file contains 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
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