File tree 2 files changed +33
-0
lines changed
2 files changed +33
-0
lines changed Original file line number Diff line number Diff line change @@ -56,9 +56,13 @@ class MultiplexMuxer extends EventEmitter {
56
56
/**
57
57
* Ends the connection and all of its streams
58
58
* @param {function(Error) } callback
59
+ * @returns {void }
59
60
*/
60
61
end ( callback ) {
61
62
callback = callback || noop
63
+ if ( this . multiplex . destroyed ) {
64
+ return nextTick ( callback )
65
+ }
62
66
this . multiplex . once ( 'close' , callback )
63
67
this . multiplex . close ( )
64
68
}
Original file line number Diff line number Diff line change
1
+ /* eslint-env mocha */
2
+ /* eslint max-nested-callbacks: ["error", 5] */
3
+ 'use strict'
4
+
5
+ const chai = require ( 'chai' )
6
+ const dirtyChai = require ( 'dirty-chai' )
7
+ const expect = chai . expect
8
+ chai . use ( require ( 'chai-checkmark' ) )
9
+ chai . use ( dirtyChai )
10
+
11
+ const pair = require ( 'pull-pair/duplex' )
12
+ const mplex = require ( '../src' )
13
+
14
+ describe ( 'Mplex' , ( ) => {
15
+ it ( 'multiple calls to end should call back' , ( done ) => {
16
+ const p = pair ( )
17
+ const dialer = mplex . dialer ( p [ 0 ] )
18
+
19
+ expect ( 2 ) . checks ( done )
20
+
21
+ dialer . end ( ( err ) => {
22
+ expect ( err ) . to . not . exist ( ) . mark ( )
23
+ } )
24
+
25
+ dialer . end ( ( err ) => {
26
+ expect ( err ) . to . not . exist ( ) . mark ( )
27
+ } )
28
+ } )
29
+ } )
You can’t perform that action at this time.
0 commit comments