How to use the webworker-promise/lib/register.TransferableResponse function in webworker-promise

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 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)
}
github Kitware / vtk-js / Sources / Filters / General / PaintFilter / PaintFilter.worker.js View on Github external
() =>
      new registerWebworker.TransferableResponse(globals.buffer.buffer, [
        globals.buffer.buffer,
      ])
  );
github Kitware / vtk-js / Sources / Interaction / Widgets / PiecewiseGaussianWidget / ComputeHistogram.worker.js View on Github external
var step = message.numberOfComponents || 1;

  var numberOfBins = message.numberOfBins;
  var delta = max - min;
  var histogram = new Float32Array(numberOfBins);
  histogram.fill(0);
  var len = array.length;
  for (var i = offset; i < len; i += step) {
    var idx = Math.floor(
      (numberOfBins - 1) * (Number(array[i]) - min) / delta
    );
    histogram[idx] += 1;
  }

  return Promise.resolve(
    new registerWebworker.TransferableResponse(histogram, [histogram.buffer])
  );
});
github InsightSoftwareConsortium / itk-js / src / WebWorkers / Pipeline.worker.js View on Github external
dataSetType.forEach((dataName) => {
            if (polyData[dataName]) {
              const data = polyData[dataName]
              data.arrays.forEach((array) => {
                if (array.data.buffer) {
                  transferables.push(array.data.buffer)
                }
              })
            }
          })
          break
      }
    })
  }

  return new registerWebworker.TransferableResponse(result, transferables)
}

webworker-promise

Promise for webworkers

MIT
Latest version published 2 years ago

Package Health Score

50 / 100
Full package analysis