Last active
December 27, 2015 05:09
-
-
Save Raynos/7272324 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
// { DATA, END, READ_ERROR, ERROR } + { PAUSE, RESUME, ABORT, ERROR, FINISH } | |
// producer | |
var producer = { | |
read: function (cb) { | |
// cb(null, DATA) | |
// cb(null, undefined | Stream.END_TOKEN) | |
// cb(READ_ERROR, undefined | Stream.END_TOKEN) | |
}, | |
abort: function (message) { | |
// consumer specific abort implementation | |
}, | |
// this ERROR is an outside of read() ERROR | |
onError: function (listener) {} | |
} | |
// consumer | |
function consumer(producer) { | |
// PAUSE is do not call .read() | |
// RESUME is call .read() one at a time sequentially | |
// ABORT is call .abort(optionalMessage) | |
// return FINI & ERROR | |
return { | |
// FINISH | |
onFinish: function (listener) {}, | |
// ERROR | |
onError: function (listener) {} | |
} | |
} | |
// however there is a third thing in play here other then consumer & producer | |
// It's the author & user of the streams | |
// if consumer or producer creates an error then it needs to be handled | |
var result = consumer(producer) | |
producer.onError(function (err) { | |
}) | |
result.onError(function (err) { | |
}) | |
result.onFinish(function () { | |
// consumer is done. | |
// continue doing stuff | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment