fix: start and stop error callback (#316)

* fix: ensure start and stop callbacks are called
This commit is contained in:
Jacob Heun
2019-02-01 16:32:34 +01:00
committed by GitHub
parent c4cab007af
commit 8047fb76fa
4 changed files with 62 additions and 6 deletions

View File

@ -17,6 +17,7 @@ const Ping = require('libp2p-ping')
const WebSockets = require('libp2p-websockets')
const ConnectionManager = require('libp2p-connection-manager')
const { emitFirst } = require('./util')
const peerRouting = require('./peer-routing')
const contentRouting = require('./content-routing')
const dht = require('./dht')
@ -194,7 +195,7 @@ class Node extends EventEmitter {
* @returns {void}
*/
start (callback = () => {}) {
this.once('start', callback)
emitFirst(this, ['error', 'start'], callback)
this.state('start')
}
@ -205,7 +206,7 @@ class Node extends EventEmitter {
* @returns {void}
*/
stop (callback = () => {}) {
this.once('stop', callback)
emitFirst(this, ['error', 'stop'], callback)
this.state('stop')
}
@ -473,8 +474,9 @@ class Node extends EventEmitter {
this._switch.stop(cb)
},
(cb) => {
// Ensures idempotent restarts
this._switch.transport.removeAll(cb)
// Ensures idempotent restarts, ignore any errors
// from removeAll, they're not useful at this point
this._switch.transport.removeAll(() => cb())
}
], (err) => {
if (err) {