https://github.com/nichoth/pull-mux
Combine and namepsace multiple streams
https://github.com/nichoth/pull-mux
Last synced: about 1 year ago
JSON representation
Combine and namepsace multiple streams
- Host: GitHub
- URL: https://github.com/nichoth/pull-mux
- Owner: nichoth
- Created: 2017-01-09T18:11:31.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2017-01-16T01:55:39.000Z (over 9 years ago)
- Last Synced: 2025-05-09T07:32:46.478Z (about 1 year ago)
- Language: JavaScript
- Homepage: https://github.com/nichoth/pull-mux#readme
- Size: 16.6 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: readme.md
Awesome Lists containing this project
README
# pull mux
Combine and namepsace multiple streams.
## install
$ npm install pull-mux
## example
```js
var test = require('tape')
var S = require('pull-stream')
var mux = require('../')
test('create a namespaced stream from an object', function (t) {
t.plan(2)
var streams = {
a: S.values([1,2,3]),
b: S.values([4,5,6])
}
var stream = mux(streams)
S(
stream,
S.collect(function (err, res) {
t.error(err)
t.deepEqual(res, [
['a', 1],
['b', 4],
['a', 2],
['b', 5],
['a', 3],
['b', 6]
], 'should namespace the events')
})
)
})
test('pass in a mux function', function (t) {
t.plan(2)
var streams = {
a: S.values([1,2]),
b: S.values([3,4])
}
var stream = mux(streams, function muxer (type, ev) {
return { type: type, data: ev }
})
S(
stream,
S.collect(function (err, res) {
t.error(err)
t.deepEqual(res, [
{ type: 'a', data: 1 },
{ type: 'b', data: 3 },
{ type: 'a', data: 2 },
{ type: 'b', data: 4 },
], 'should map the events')
})
)
})
```