diff --git a/package.json b/package.json index 6017e65..5c3e0c0 100644 --- a/package.json +++ b/package.json @@ -51,16 +51,16 @@ "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", "lodash.contains": "^2.4.3", - "multistream-select": "^0.6.5", "multiaddr": "^1.4.0", + "multistream-select": "^0.6.5", "peer-id": "^0.6.6", "peer-info": "^0.6.2", - "protocol-buffers-stream": "^1.3.1" + "protocol-buffers-stream": "^1.3.1", + "run-parallel": "^1.1.6" }, "aegir": { "webpack": { diff --git a/src/index.js b/src/index.js index 304d6cc..0f0bb3d 100644 --- a/src/index.js +++ b/src/index.js @@ -1,12 +1,12 @@ 'use strict' -const async = require('async') const multistream = require('multistream-select') const identify = require('./identify') const DuplexPassThrough = require('duplex-passthrough') const contains = require('lodash.contains') const util = require('util') const EE = require('events').EventEmitter +const parallel = require('run-parallel') exports = module.exports = Swarm @@ -378,17 +378,9 @@ function Swarm (peerInfo) { this.muxedConns[key].muxer.end() }) - async.each( - Object.keys(this.transports), - (key, cb) => { - // avoid unhandled error messages - this.transports[key].once('error', (err) => { - console.log('got error', err) - }) - this.transports[key].close(cb) - }, - callback - ) + parallel(Object.keys(this.transports).map((key) => { + return (cb) => this.transports[key].close(cb) + }), callback) } } diff --git a/test/01-transport-tcp.node.js b/test/01-transport-tcp.node.js index 15a8452..2b18105 100644 --- a/test/01-transport-tcp.node.js +++ b/test/01-transport-tcp.node.js @@ -3,7 +3,7 @@ const expect = require('chai').expect -const async = require('async') +const parallel = require('run-parallel') const multiaddr = require('multiaddr') const Peer = require('peer-info') const Swarm = require('../src') @@ -93,7 +93,7 @@ describe('transport - tcp', function () { }) it('close', (done) => { - async.parallel([ + parallel([ (cb) => swarmA.transport.close('tcp', cb), (cb) => swarmB.transport.close('tcp', cb) ], done) diff --git a/test/03-transport-websockets.node.js b/test/03-transport-websockets.node.js index 6fdca5d..a1a06e1 100644 --- a/test/03-transport-websockets.node.js +++ b/test/03-transport-websockets.node.js @@ -3,7 +3,7 @@ const expect = require('chai').expect -const async = require('async') +const parallel = require('run-parallel') const multiaddr = require('multiaddr') const Peer = require('peer-info') const Swarm = require('../src') @@ -89,7 +89,7 @@ describe('transport - websockets', function () { }) it('close', (done) => { - async.parallel([ + parallel([ (cb) => swarmA.transport.close('ws', cb), (cb) => swarmB.transport.close('ws', cb) ], done) diff --git a/test/04-muxing-multiplex.node.js b/test/04-muxing-multiplex.node.js index 860a0f9..0f0e18d 100644 --- a/test/04-muxing-multiplex.node.js +++ b/test/04-muxing-multiplex.node.js @@ -3,7 +3,7 @@ const expect = require('chai').expect -const async = require('async') +const parallel = require('run-parallel') const multiaddr = require('multiaddr') const Peer = require('peer-info') const Swarm = require('../src') @@ -41,7 +41,7 @@ describe('stream muxing with multiplex (on TCP)', function () { swarmB.transport.add('tcp', new TCP()) swarmC.transport.add('tcp', new TCP()) - async.parallel([ + parallel([ (cb) => swarmA.transport.listen('tcp', {}, null, cb), (cb) => swarmB.transport.listen('tcp', {}, null, cb), (cb) => swarmC.transport.listen('tcp', {}, null, cb) @@ -49,7 +49,7 @@ describe('stream muxing with multiplex (on TCP)', function () { }) after((done) => { - async.parallel([ + parallel([ (cb) => swarmA.close(cb), (cb) => swarmB.close(cb), (cb) => swarmC.close(cb) diff --git a/test/05-muxing-spdy.node.js b/test/05-muxing-spdy.node.js index 250e5b5..9ed39a4 100644 --- a/test/05-muxing-spdy.node.js +++ b/test/05-muxing-spdy.node.js @@ -3,7 +3,7 @@ const expect = require('chai').expect -const async = require('async') +const parallel = require('run-parallel') const multiaddr = require('multiaddr') const Peer = require('peer-info') const Swarm = require('../src') @@ -11,7 +11,7 @@ const TCP = require('libp2p-tcp') const spdy = require('libp2p-spdy') describe('stream muxing with spdy (on TCP)', function () { - this.timeout(20000) + this.timeout(60 * 1000) var swarmA var peerA @@ -41,7 +41,7 @@ describe('stream muxing with spdy (on TCP)', function () { swarmB.transport.add('tcp', new TCP()) swarmC.transport.add('tcp', new TCP()) - async.parallel([ + parallel([ (cb) => swarmA.transport.listen('tcp', {}, null, cb), (cb) => swarmB.transport.listen('tcp', {}, null, cb), (cb) => swarmC.transport.listen('tcp', {}, null, cb) @@ -49,7 +49,7 @@ describe('stream muxing with spdy (on TCP)', function () { }) after((done) => { - async.parallel([ + parallel([ (cb) => swarmA.close(cb), (cb) => swarmB.close(cb), (cb) => swarmC.close(cb) diff --git a/test/08-swarm-without-muxing.node.js b/test/08-swarm-without-muxing.node.js index f16d409..7463eb0 100644 --- a/test/08-swarm-without-muxing.node.js +++ b/test/08-swarm-without-muxing.node.js @@ -3,7 +3,7 @@ const expect = require('chai').expect -const async = require('async') +const parallel = require('run-parallel') const multiaddr = require('multiaddr') const Peer = require('peer-info') const Swarm = require('../src') @@ -43,7 +43,7 @@ describe('high level API - 1st without stream multiplexing (on TCP)', function ( }) after((done) => { - async.parallel([ + parallel([ (cb) => swarmA.close(cb), (cb) => swarmB.close(cb) ], done) diff --git a/test/09-swarm-with-muxing.node.js b/test/09-swarm-with-muxing.node.js index a58cdcf..f904ea8 100644 --- a/test/09-swarm-with-muxing.node.js +++ b/test/09-swarm-with-muxing.node.js @@ -3,7 +3,7 @@ const expect = require('chai').expect -const async = require('async') +const parallel = require('run-parallel') const multiaddr = require('multiaddr') const Peer = require('peer-info') const Swarm = require('../src') @@ -46,7 +46,7 @@ describe('high level API - with everything mixed all together!', function () { }) after((done) => { - async.parallel([ + parallel([ (cb) => swarmA.close(cb), (cb) => swarmB.close(cb), // (cb) => swarmC.close(cb),