How to use the @parcel/workers.getWorkerApi function in @parcel/workers

To help you get started, we’ve selected a few @parcel/workers 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 / fs / src / MemoryFS.js View on Github external
constructor(id: number, handleFn: HandleFunction) {
    // TODO Make this not a subclass
    // $FlowFixMe
    super();
    this.id = id;
    this.handleFn = handleFn;

    handleFn('_registerWorker', [
      WorkerFarm.getWorkerApi().createReverseHandle(event => {
        switch (event.type) {
          case 'writeFile':
            this.files.set(event.path, event.entry);
            break;
          case 'unlink':
            this.files.delete(event.path);
            this.dirs.delete(event.path);
            this.symlinks.delete(event.path);
            break;
          case 'mkdir':
            this.dirs.set(event.path, new Directory());
            break;
          case 'symlink':
            this.symlinks.set(event.path, event.target);
            break;
        }
github parcel-bundler / parcel / packages / core / package-manager / src / installPackage.js View on Github external
export function installPackage(
  fs: FileSystem,
  modules: Array,
  filePath: FilePath,
  options?: InstallOptions,
): Promise {
  if (WorkerFarm.isWorker()) {
    let workerApi = WorkerFarm.getWorkerApi();
    return workerApi.callMaster({
      location: __filename,
      args: [fs, modules, filePath, options],
      method: '_addToInstallQueue',
    });
  }

  return _addToInstallQueue(fs, modules, filePath, options);
}