aboutsummaryrefslogtreecommitdiffstats
path: root/app/scripts/lib
diff options
context:
space:
mode:
authorkumavis <aaron@kumavis.me>2016-04-15 12:22:04 +0800
committerkumavis <aaron@kumavis.me>2016-04-15 12:22:04 +0800
commit907e39e5abc301fa54e144c5c151b79c3affb788 (patch)
treefcefefc50d3bb7452e91e507b437805a48c9e929 /app/scripts/lib
parentcef1f2a65f27d594b12afd021dea73fcaf569af5 (diff)
downloadtangerine-wallet-browser-907e39e5abc301fa54e144c5c151b79c3affb788.tar
tangerine-wallet-browser-907e39e5abc301fa54e144c5c151b79c3affb788.tar.gz
tangerine-wallet-browser-907e39e5abc301fa54e144c5c151b79c3affb788.tar.bz2
tangerine-wallet-browser-907e39e5abc301fa54e144c5c151b79c3affb788.tar.lz
tangerine-wallet-browser-907e39e5abc301fa54e144c5c151b79c3affb788.tar.xz
tangerine-wallet-browser-907e39e5abc301fa54e144c5c151b79c3affb788.tar.zst
tangerine-wallet-browser-907e39e5abc301fa54e144c5c151b79c3affb788.zip
wiring - move to obj-multiplex
Diffstat (limited to 'app/scripts/lib')
-rw-r--r--app/scripts/lib/obj-multiplex.js41
1 files changed, 41 insertions, 0 deletions
diff --git a/app/scripts/lib/obj-multiplex.js b/app/scripts/lib/obj-multiplex.js
new file mode 100644
index 000000000..333b6061f
--- /dev/null
+++ b/app/scripts/lib/obj-multiplex.js
@@ -0,0 +1,41 @@
+const through = require('through2')
+
+module.exports = ObjectMultiplex
+
+
+function ObjectMultiplex(opts){
+ opts = opts || {}
+ // create multiplexer
+ var mx = through.obj(function(chunk, enc, cb) {
+ var name = chunk.name
+ var data = chunk.data
+ var substream = mx.streams[name]
+ if (!substream) {
+ console.warn("orphaned data for stream " + name)
+ } else {
+ substream.push(data)
+ }
+ return cb()
+ })
+ mx.streams = {}
+ // create substreams
+ mx.createStream = function(name) {
+ var substream = mx.streams[name] = through.obj(function(chunk, enc, cb) {
+ mx.push({
+ name: name,
+ data: chunk,
+ })
+ return cb()
+ })
+ mx.on('end', function() {
+ return substream.emit('end')
+ })
+ if (opts.error) {
+ mx.on('error', function() {
+ return substream.emit('error')
+ })
+ }
+ return substream
+ }
+ return mx
+}