src/client.js
/**
   * Remote procedure call. Only ArrayBuffers will be transferred automatically (not TypedArrays).
   * Error would be thrown, if:
   * - it happened during procedure
   * - you try to call an unexisted procedure
   * - procedure execution takes more than timeout
   * @param  {string}     method                 Remote procedure name
   * @param  {*}          data                   Request data
   * @param  {Object}     [options]              Options
   * @param  {number}     [options.timeout=2000] Wait timeout
   * @return {Promise<*>}                        Remote procedure promise
   */
Remote procedure call. Only ArrayBuffers will be transferred automatically (not TypedArrays).
Remote procedure call . Only ArrayBuffers will be transferred automatically ( not TypedArrays ) .
call (method, data, { timeout = 2000 } = {}) {
    var uid = uuid()
    var transferables = peekTransferables(data)
    return new Promise((resolve, reject) => {
      this.timeouts[uid] = setTimeout(() => this.reject(uid, `Timeout exceeded for RPC method "${method}"`), timeout)
      this.calls[uid] = resolve
      this.errors[uid] = reject
      this.workers[this.idx].postMessage({ method, uid, data }, transferables)
      this.idx = ++this.idx % this.workers.length 
    })
  }
call ( method , data , { timeout = 2000 } = { } ) { var uid = uuid ( ) var transferables = peekTransferables ( data ) return new Promise ( ( resolve , reject ) => { this . timeouts [ uid ] = setTimeout ( ( ) => this . reject ( uid , ` ${ method } ` ) , timeout ) this . calls [ uid ] = resolve this . errors [ uid ] = reject this . workers [ this . idx ] . postMessage ( { method , uid , data } , transferables ) this . idx = ++ this . idx % this . workers . length } ) }
Remote procedure call.
Remote procedure call .
// round robin