1 | var pull = require('pull-stream')
|
2 | var mux = require('../')
|
3 | var tape = require('tape')
|
4 | var Pushable = require('pull-pushable')
|
5 |
|
6 | function delay(fun) {
|
7 | return function (a, b) {
|
8 | setImmediate(function () {
|
9 | fun(a, b)
|
10 | })
|
11 | }
|
12 | }
|
13 |
|
14 |
|
15 | var client = {
|
16 | echo : 'duplex',
|
17 | }
|
18 |
|
19 | module.exports = function (codec) {
|
20 |
|
21 | tape('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 |
|
51 |
|
52 |
|
53 | }
|
54 |
|
55 | if(!module.parent) module.exports(function (e) { return e })
|
56 |
|
57 |
|
58 |
|
59 |
|
60 |
|
61 |
|
62 |
|
63 |
|