Skip to content
This repository has been archived by the owner on Aug 23, 2019. It is now read-only.

Commit

Permalink
fix: call cb in close after all transport are closed
Browse files Browse the repository at this point in the history
  • Loading branch information
dignifiedquire committed May 6, 2016
1 parent fb56cc3 commit 85a0647
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
"stream-pair": "^1.0.3"
},
"dependencies": {
"async": "^2.0.0-rc.4",
"babel-runtime": "^6.6.1",
"duplex-passthrough": "github:diasdavid/duplex-passthrough",
"ip-address": "^5.8.0",
Expand All @@ -78,4 +79,4 @@
"Richard Littauer <richard.littauer@gmail.com>",
"dignifiedquire <dignifiedquire@gmail.com>"
]
}
}
18 changes: 9 additions & 9 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
'use strict'

const async = require('async')
const multistream = require('multistream-select')
const identify = require('./identify')
const DuplexPassThrough = require('duplex-passthrough')
Expand Down Expand Up @@ -367,19 +368,18 @@ function Swarm (peerInfo) {
}

this.close = (callback) => {
var count = 0

Object.keys(this.muxedConns).forEach((key) => {
this.muxedConns[key].muxer.end()
})

Object.keys(this.transports).forEach((key) => {
this.transports[key].close(() => {
if (++count === Object.keys(this.transports).length) {
callback()
}
})
})
async.each(
Object.keys(this.transports),
(key, cb) => this.transports[key].close(cb),
() => {
// Ignoring close errors
callback()
}
)
}
}

Expand Down

0 comments on commit 85a0647

Please sign in to comment.