How to use webworker-promise - 10 common examples

To help you get started, we’ve selected a few webworker-promise 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 Kitware / paraview-glance / app / itk / createWebworkerPromise.js View on Github external
if (webWorkerUrl.startsWith('http')) {
    return axios.get(webWorkerUrl, {
      responseType: 'blob'
    }).then(function (response) {
      var worker = new window.Worker(URL.createObjectURL(response.data) // eslint-disable-line
      );
      var webworkerPromise = new WebworkerPromise(worker);
      return {
        webworkerPromise: webworkerPromise,
        worker: worker
      };
    });
  }

  var worker = new window.Worker(webWorkerUrl);
  var webworkerPromise = new WebworkerPromise(worker);
  return Promise.resolve({
    webworkerPromise: webworkerPromise,
    worker: worker
  });
};
github Kitware / paraview-glance / app / itk / createWebworkerPromise.js View on Github external
}).then(function (response) {
      var worker = new window.Worker(URL.createObjectURL(response.data) // eslint-disable-line
      );
      var webworkerPromise = new WebworkerPromise(worker);
      return {
        webworkerPromise: webworkerPromise,
        worker: worker
      };
    });
  }
github Kitware / paraview-glance / app / itk / createWebworkerPromise.js View on Github external
var createWebworkerPromise = function createWebworkerPromise(name, existingWorker) {
  if (existingWorker) {
    var _webworkerPromise = new WebworkerPromise(existingWorker);

    return Promise.resolve({
      webworkerPromise: _webworkerPromise,
      worker: existingWorker
    });
  }

  var webWorkerUrl = "".concat(config.itkModulesPath, "/WebWorkers/").concat(name, ".worker.js");

  if (webWorkerUrl.startsWith('http')) {
    return axios.get(webWorkerUrl, {
      responseType: 'blob'
    }).then(function (response) {
      var worker = new window.Worker(URL.createObjectURL(response.data) // eslint-disable-line
      );
      var webworkerPromise = new WebworkerPromise(worker);
github Kitware / vtk-js / Sources / Rendering / OpenGL / Texture / index.js View on Github external
reformattedGradients
        );

        publicAPI.deactivate();
        return true;
      };
    }

    const maxNumberOfWorkers = 4;
    const depthStride = Math.ceil(depth / maxNumberOfWorkers);
    const workerPromises = [];
    const workers = [];
    let depthIndex = 0;
    while (depthIndex < depth - 1) {
      const worker = new ComputeGradientsWorker();
      const workerPromise = new WebworkerPromise(worker);
      const depthStart = depthIndex;
      let depthEnd = depthIndex + depthStride; // no -1 to include one more slice to compute gradient
      depthEnd = Math.min(depthEnd, depth - 1);
      const subData = new data.constructor(
        data.slice(depthStart * width * height, (depthEnd + 1) * width * height) // +1 to include data from slice at depthEnd
      );
      workers.push(worker);
      workerPromises.push(
        workerPromise.postMessage(
          {
            width,
            height,
            depth,
            spacing,
            data: subData,
            haveWebgl2,
github Kitware / vtk-js / Sources / Filters / General / PaintFilter / PaintFilter.worker.js View on Github external
thresh[ii] -= delta[ii];
              if (thresh[ii] < 0) {
                thresh[ii] = step;
                pt[ii] += inc[ii];
              }
            }
          }
        }
      }
    }
  }

  globals.prevPoint = point;
}

registerWebworker()
  .operation('start', ({ bufferType, dimensions }) => {
    const bufferSize = dimensions[0] * dimensions[1] * dimensions[2];
    /* eslint-disable-next-line */
    globals.buffer = new self[bufferType](bufferSize);
    globals.dimensions = dimensions;
    globals.prevPoint = null;
  })
  .operation('paint', handlePaint)
  .operation(
    'end',
    () =>
      new registerWebworker.TransferableResponse(globals.buffer.buffer, [
        globals.buffer.buffer,
      ])
  );
github InsightSoftwareConsortium / itk-js / src / WebWorkers / ImageIO.worker.js View on Github external
}

  let ioModule = null
  if (io in ioToModule) {
    ioModule = ioToModule[io]
  } else {
    ioToModule[io] = loadEmscriptenModule(input.config.itkModulesPath, 'ImageIOs', io)
    ioModule = ioToModule[io]
  }

  const filePath = mountpoint + '/' + input.name
  ioModule.mkdirs(mountpoint)
  writeImageEmscriptenFSFile(ioModule, input.useCompression, input.image, filePath)
  const writtenFile = ioModule.readFile(filePath, { encoding: 'binary' })

  return new registerWebworker.TransferableResponse(writtenFile.buffer, [writtenFile.buffer])
}
github InsightSoftwareConsortium / itk-js / src / WebWorkers / ImageIO.worker.js View on Github external
if (!seriesReaderModule) {
    seriesReaderModule = loadEmscriptenModule(input.config.itkModulesPath, 'ImageIOs', seriesReader)
  }

  const blobs = input.fileDescriptions.map((fileDescription) => {
    const blob = new Blob([fileDescription.data])
    return { name: fileDescription.name, data: blob }
  })
  const mountpoint = '/work'
  seriesReaderModule.mountBlobs(mountpoint, blobs)
  const filePath = mountpoint + '/' + input.fileDescriptions[0].name
  const image = readImageEmscriptenFSDICOMFileSeries(seriesReaderModule,
    mountpoint, filePath)
  seriesReaderModule.unmountBlobs(mountpoint)

  return new registerWebworker.TransferableResponse(image, [image.data.buffer])
}
github InsightSoftwareConsortium / itk-js / src / WebWorkers / ImageIO.worker.js View on Github external
let ioModule = null
  if (io in ioToModule) {
    ioModule = ioToModule[io]
  } else {
    ioToModule[io] = loadEmscriptenModule(input.config.itkModulesPath, 'ImageIOs', io)
    ioModule = ioToModule[io]
  }

  const blob = new Blob([input.data])
  const blobs = [{ name: input.name, data: blob }]
  ioModule.mountBlobs(mountpoint, blobs)
  const filePath = mountpoint + '/' + input.name
  const image = readImageEmscriptenFSFile(ioModule, filePath)
  ioModule.unmountBlobs(mountpoint)

  return new registerWebworker.TransferableResponse(image, [image.data.buffer])
}
github InsightSoftwareConsortium / itk-js / src / WebWorkers / MeshIO.worker.js View on Github external
let ioModule = null
  if (io in ioToModule) {
    ioModule = ioToModule[io]
  } else {
    ioToModule[io] = loadEmscriptenModule(input.config.itkModulesPath, 'MeshIOs', io)
    ioModule = ioToModule[io]
  }

  const filePath = mountpoint + '/' + input.name
  ioModule.mkdirs(mountpoint)
  writeMeshEmscriptenFSFile(ioModule,
    { useCompression: input.useCompression, binaryFileType: input.binaryFileType },
    input.mesh, filePath)
  const writtenFile = ioModule.readFile(filePath, { encoding: 'binary' })

  return new registerWebworker.TransferableResponse(writtenFile.buffer, [writtenFile.buffer])
}
github InsightSoftwareConsortium / itk-js / src / WebWorkers / MeshIO.worker.js View on Github external
ioModule.unmountBlobs(mountpoint)

  const transferables = []
  if (mesh.points) {
    transferables.push(mesh.points.buffer)
  }
  if (mesh.pointData) {
    transferables.push(mesh.pointData.buffer)
  }
  if (mesh.cells) {
    transferables.push(mesh.cells.buffer)
  }
  if (mesh.cellData) {
    transferables.push(mesh.cellData.buffer)
  }
  return new registerWebworker.TransferableResponse(mesh, transferables)
}

webworker-promise

Promise for webworkers

MIT
Latest version published 2 years ago

Package Health Score

50 / 100
Full package analysis