Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var Sink = function(expected, timeout, callback) {
- var defaultTimeout = 1000;
- if(typeof timeout == 'function') {
- callback = timeout;
- timeout = defaultTimeout;
- }
- timeout = timeout || defaultTimeout;
- var internalCount = 0;
- var kill = function() {
- assert.ok(false, "Did not reach expected " + expected + " with an idle timeout of " + timeout);
- }
- var killTimeout = setTimeout(kill, timeout);
- return {
- add: function(count) {
- count = count || 1;
- internalCount += count;
- clearTimeout(killTimeout)
- if(internalCount < expected) {
- killTimeout = setTimeout(kill, timeout)
- }
- else {
- assert.equal(internalCount, expected);
- callback();
- }
- }
- }
- }
Add Comment
Please, Sign In to add comment