-
-
Save chrisdickinson/fe0b99e34f099cfc6b57 to your computer and use it in GitHub Desktop.
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
var addLatency = function() { | |
var pending = 0 | |
, stream | |
, ended | |
return stream = through(write, end) | |
function write(buf) { | |
++pending | |
setTimeout(function() { | |
--pending | |
stream.queue(buf) | |
check() | |
}, 1000 * Math.random()) | |
} | |
function end() { | |
ended = true | |
check() | |
} | |
function check() { | |
if(!pending && ended) { | |
return stream.queue(null) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment