How to use the @parcel/utils.serialize function in @parcel/utils

To help you get started, we’ve selected a few @parcel/utils examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github parcel-bundler / parcel / packages / core / workers / src / process / ProcessWorker.js View on Github external
send(data: WorkerMessage) {
    if (!this.processQueue) {
      this.sendQueue.push(data);
      return;
    }

    let result = this.child.send(serialize(data).toString('base64'), error => {
      if (error && error instanceof Error) {
        // Ignore this, the workerfarm handles child errors
        return;
      }

      this.processQueue = true;

      if (this.sendQueue.length > 0) {
        let queueCopy = this.sendQueue.slice(0);
        this.sendQueue = [];
        queueCopy.forEach(entry => this.send(entry));
      }
    });

    if (!result || /^win/.test(process.platform)) {
      // Queue is handling too much messages throttle it
github parcel-bundler / parcel / packages / core / workers / src / WorkerFarm.js View on Github external
callMaster: async (
      request: CallRequest,
      awaitResponse: ?boolean = true,
    ): Promise => {
      // $FlowFixMe
      let result = await this.processRequest({
        ...request,
        awaitResponse,
      });
      return deserialize(serialize(result));
    },
    createReverseHandle: (fn: HandleFunction): Handle =>
github parcel-bundler / parcel / packages / core / workers / src / process / ProcessChild.js View on Github external
send(data: WorkerMessage) {
    let processSend = nullthrows(process.send).bind(process);
    processSend(serialize(data).toString('base64'), err => {
      if (err && err instanceof Error) {
        if (err.code === 'ERR_IPC_CHANNEL_CLOSED') {
          // IPC connection closed
          // no need to keep the worker running if it can't send or receive data
          return this.stop();
        }
      }
    });
  }
github parcel-bundler / parcel / packages / core / cache / src / Cache.js View on Github external
async set(key: string, value: mixed) {
    try {
      let blobPath = this._getCachePath(key);
      let data = serialize(value);

      await this.fs.writeFile(blobPath, data);
      return key;
    } catch (err) {
      logger.error(err, '@parcel/cache');
    }
  }
}
github parcel-bundler / parcel / packages / core / cache / src / FSCache.js View on Github external
async set(key: string, value: mixed) {
    try {
      let blobPath = this._getCachePath(key);
      let data = serialize(value);

      await this.fs.writeFile(blobPath, data);
      return key;
    } catch (err) {
      logger.error(`Error writing to cache: ${err.message}`);
    }
  }
}
github parcel-bundler / parcel / packages / core / cache / src / HTTPCache.js View on Github external
async set(key: string, value: mixed) {
    await this.request(this._getCachePath(key), {
      method: 'put',
      body: serialize(value),
      headers: {
        'content-type': 'application/octet-stream'
      }
    });
    return key;
  }
}