src/MasterElector.js
function _broadcastMessage (type, data) {
    data = data || {}
    let message = {type, data}
    let { host, coordinationPort } = node.settings
    dns.resolve4(host, (err, addresses) => {
      if (err) {
        debug(`cannot resolve host '${host}'. Check DNS infrastructure.`)
        return
      }
      debug(`broadcasting message '${type}' to '${host}' nodes: ${addresses}`)
      addresses.forEach(address => {
        let messenger = zmq.socket('req')
        messenger.connect(`tcp://${address}:${coordinationPort}`)
        messenger.send(JSON.stringify({
          ...message,
          toAddress: address
        }))

        let _end = false
        function closeSocket () {
          if (_end) return
          _end = true
          messenger.close()
        }

        messenger.on('message', closeSocket)
        setTimeout(closeSocket, 300)
      })
    })
  }
function _broadcastMessage (type, data) {
    data = data || {}
    let message = {type, data}
    let { host, coordinationPort } = node.settings
    dns.resolve4(host, (err, addresses) => {
      if (err) {
        debug(`cannot resolve host '${host}'. Check DNS infrastructure.`)
        return
      }
      debug(`broadcasting message '${type}' to '${host}' nodes: ${addresses}`)
      addresses.forEach(address => {
        let messenger = zmq.socket('req')
        messenger.connect(`tcp://${address}:${coordinationPort}`)
        messenger.send(JSON.stringify({
          ...message,
          toAddress: address
        }))

        let _end = false
        function closeSocket () {
          if (_end) return
          _end = true
          messenger.close()
        }

        messenger.on('message', closeSocket)
        setTimeout(closeSocket, 300)
      })
    })
  }
function _broadcastMessage ( type , data ) { data = data || { } let message = { type , data } let { host , coordinationPort } = node . settings dns . resolve4 ( host , ( err , addresses ) => { if ( err ) { debug ( ` ${ host } ` ) return } debug ( ` ${ type } ${ host } ${ addresses } ` ) addresses . forEach ( address => { let messenger = zmq . socket ( 'req' ) messenger . connect ( ` ${ address } ${ coordinationPort } ` ) messenger . send ( JSON . stringify ( { ... message , toAddress : address } ) ) let _end = false function closeSocket ( ) { if ( _end ) return _end = true messenger . close ( ) } messenger . on ( 'message' , closeSocket ) setTimeout ( closeSocket , 300 ) } ) } ) }
broadcasts a message to the coordination socket of all the dnsNodes
@param  {string} type - Type of message
@param  {object} data - Payload of the message
broadcasts a message to the coordination socket of all the dnsNodes