UNPKG

1.02 kBJavaScriptView Raw
1var pull = require('pull-stream')
2var mux = require('../')
3var tape = require('tape')
4var Pushable = require('pull-pushable')
5
6function delay(fun) {
7 return function (a, b) {
8 setImmediate(function () {
9 fun(a, b)
10 })
11 }
12}
13
14
15var client = {
16 echo : 'duplex',
17}
18
19module.exports = function (codec) {
20
21tape('close after both sides of a duplex stream ends', function (t) {
22
23 var A = mux(client, null, codec) ()
24 var B = mux(null, client, codec) ({
25 })
26
27 var bs = B.createStream()
28 var as = A.createStream()
29
30 var source = Pushable()
31
32 pull(
33 function (err, cb) {
34 if(!err) setTimeout(function () { cb(null, Date.now()) })
35 else console.log('ERROR', err)
36 },
37 A.echo(function (err) {
38 console.error('caught err')
39 }),
40 pull.collect(function (err, ary) {
41 t.ok(err)
42 t.end()
43 })
44 )
45
46 pull(as, bs, as)
47
48})
49
50//TODO: write test for when it's a duplex api that
51//is missing on the remote!!!
52
53}
54
55if(!module.parent) module.exports(function (e) { return e })
56
57
58
59
60
61
62
63