Skip to content

Instantly share code, notes, and snippets.

@chrisdickinson
Created August 16, 2013 21:57
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 chrisdickinson/fe0b99e34f099cfc6b57 to your computer and use it in GitHub Desktop.
Save chrisdickinson/fe0b99e34f099cfc6b57 to your computer and use it in GitHub Desktop.
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