src/Node.js
function deactivate () {
    if (!_active || _deactivating) return node
    debug('deactivating')

    if (external) {
      _active = false
      _subConnection.disconnect()
      _pubConnection.disconnect()
      node.emit('deactivated')
    } else {
      _deactivating = true
      let ensuredMaster = Promise.resolve()

      const isMaster = _subConnection.master && _subConnection.master.name === _name

      if (isMaster) {
        debug(`I'm the master node. I will try to elect another master before disconnecting.`)

        let advertiseId = `zz-zzzzzzzz-${_id}`
        ensuredMaster = _masterResolver
                        .resolve(advertiseId)
                        .then(master => {
                          debug(`successfully elected a new master: ${master.name}`)
                          try {
                            _masterBroker.signalNewMaster(master)
                          } catch (e) {
                            console.log(e)
                          }
                        })
                        .catch(() => {
                          debug(`failed to elect a new master. Disconnecting anyway.`)
                        })
      }

      ensuredMaster
      .then(() => {
        _subConnection.disconnect()
        _pubConnection.disconnect()
        _masterResolver.unbind()
        let timeout = isMaster ? 1000 : 1
        setTimeout(() => {
          debug('deactivated')
          node.emit('deactivated')
          _masterBroker.unbind()
        }, timeout)
      })
    }

    return node
  }
function deactivate () {
    if (!_active || _deactivating) return node
    debug('deactivating')

    if (external) {
      _active = false
      _subConnection.disconnect()
      _pubConnection.disconnect()
      node.emit('deactivated')
    } else {
      _deactivating = true
      let ensuredMaster = Promise.resolve()

      const isMaster = _subConnection.master && _subConnection.master.name === _name

      if (isMaster) {
        debug(`I'm the master node. I will try to elect another master before disconnecting.`)

        let advertiseId = `zz-zzzzzzzz-${_id}`
        ensuredMaster = _masterResolver
                        .resolve(advertiseId)
                        .then(master => {
                          debug(`successfully elected a new master: ${master.name}`)
                          try {
                            _masterBroker.signalNewMaster(master)
                          } catch (e) {
                            console.log(e)
                          }
                        })
                        .catch(() => {
                          debug(`failed to elect a new master. Disconnecting anyway.`)
                        })
      }

      ensuredMaster
      .then(() => {
        _subConnection.disconnect()
        _pubConnection.disconnect()
        _masterResolver.unbind()
        let timeout = isMaster ? 1000 : 1
        setTimeout(() => {
          debug('deactivated')
          node.emit('deactivated')
          _masterBroker.unbind()
        }, timeout)
      })
    }

    return node
  }
function deactivate ( ) { if ( ! _active || _deactivating ) return node debug ( 'deactivating' ) if ( external ) { _active = false _subConnection . disconnect ( ) _pubConnection . disconnect ( ) node . emit ( 'deactivated' ) } else { _deactivating = true let ensuredMaster = Promise . resolve ( ) const isMaster = _subConnection . master && _subConnection . master . name === _name if ( isMaster ) { debug ( ` ` ) let advertiseId = ` ${ _id } ` ensuredMaster = _masterResolver . resolve ( advertiseId ) . then ( master => { debug ( ` ${ master . name } ` ) try { _masterBroker . signalNewMaster ( master ) } catch ( e ) { console . log ( e ) } } ) . catch ( ( ) => { debug ( ` ` ) } ) } ensuredMaster . then ( ( ) => { _subConnection . disconnect ( ) _pubConnection . disconnect ( ) _masterResolver . unbind ( ) let timeout = isMaster ? 1000 : 1 setTimeout ( ( ) => { debug ( 'deactivated' ) node . emit ( 'deactivated' ) _masterBroker . unbind ( ) } , timeout ) } ) } return node }
Starts the node's deactivation routine
@return {object} node instance
Starts the node s deactivation routine