-
-
Save chrisdickinson/6ba25896cf7b8463065b 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 oneToOne = function(innerWrite, innerEnd) { | |
var stream = through(write, end) | |
, pending = 0 | |
, queue | |
, ended | |
, abort | |
queue = stream.queue | |
stream.queue = _queue | |
return stream | |
function _queue(what) { | |
--pending | |
if(what === null) { | |
abort = true | |
} | |
queue.call(stream, what) | |
return check() | |
} | |
function write(datum) { | |
++pending | |
innerWrite.call(stream, datum) | |
} | |
function end() { | |
ended = true | |
check() | |
} | |
function check() { | |
if(pending || abort) { | |
return | |
} | |
innerEnd.call(stream) | |
if(abort) { | |
return | |
} | |
queue.call(stream, null) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment