lib/synchronization/socket-emitter.js
function request (event, data) {
    return new Promise(function (resolve, reject) {
      // put the data in an envelope with id
      var id = getId();
      var envelope = {
        event: event,
        id: id,
        data: data
      };

      // add the request to the list with requests in progress
      queue[id] = {
        resolve: resolve,
        reject: reject,
        timeout: setTimeout(function () {
          delete queue[id];
          reject(new Error('Timeout'));
        }, TIMEOUT)
      };

      debug('request', envelope);
      socket.send(JSON.stringify(envelope));
    }).catch(function (err) {console.log('ERROR', err)});
  }
function request (event, data) {
    return new Promise(function (resolve, reject) {
      // put the data in an envelope with id
      var id = getId();
      var envelope = {
        event: event,
        id: id,
        data: data
      };

      // add the request to the list with requests in progress
      queue[id] = {
        resolve: resolve,
        reject: reject,
        timeout: setTimeout(function () {
          delete queue[id];
          reject(new Error('Timeout'));
        }, TIMEOUT)
      };

      debug('request', envelope);
      socket.send(JSON.stringify(envelope));
    }).catch(function (err) {console.log('ERROR', err)});
  }
function request ( event , data ) { return new Promise ( function ( resolve , reject ) { // put the data in an envelope with id var id = getId ( ) ; var envelope = { event : event , id : id , data : data } ; // add the request to the list with requests in progress queue [ id ] = { resolve : resolve , reject : reject , timeout : setTimeout ( function ( ) { delete queue [ id ] ; reject ( new Error ( 'Timeout' ) ) ; } , TIMEOUT ) } ; debug ( 'request' , envelope ) ; socket . send ( JSON . stringify ( envelope ) ) ; } ) . catch ( function ( err ) { console . log ( 'ERROR' , err ) } ) ; }
Request an event, await a response
@param {string} event
@param {*} data
@return {Promise} Returns a promise which resolves with the reply
Request an event await a response