How to use the threads.Transfer function in threads

To help you get started, we’ve selected a few threads 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 ceresimaging / fast-lzw / index.js View on Github external
prepareDataForTransfer (typedArrays) {
    const transfers = []
    return Transfer(
      typedArrays.map(function (typedArray) {
        if (typedArray.buffer instanceof SharedArrayBuffer) {
          return typedArray
        } else {
          if (typedArray.byteLength != typedArray.buffer.byteLength) {
            // If the typedArray doesn't span the buffer, lets play it safe and make a copy
            typedArray = typedArray.slice()
          }
          transfers.push(typedArray.buffer)
          return typedArray
        }
      }), 
      transfers
    )
  }
  async decompress(typedArrays) {