How to use the comlink.transfer function in comlink

To help you get started, we’ve selected a few comlink 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 transcend-io / penumbra / src / API.ts View on Github external
await new DecryptionChannel().then(async (thread: PenumbraWorkerAPI) => {
      /**
       * PenumbraWorkerAPI.encrypt calls require('./encrypt').encrypt()
       * from the worker thread and starts reading the input stream from
       * [remoteWritableStream.writable]
       */
      thread.decrypt(
        options,
        ids,
        sizes,
        transfer(readablePorts, readablePorts),
        transfer(writablePorts, writablePorts),
      );
    });
    // encryption jobs submitted and still processing
github ritz078 / raaga / components / Visualizer / Visualizer.tsx View on Github external
(async function() {
      const canvas: any =
        offScreenCanvasSupport === OFFSCREEN_2D_CANVAS_SUPPORT.SUPPORTED
          ? canvasRef.current.transferControlToOffscreen()
          : canvasRef.current;

      // This has been done because it wasn't getting correctly transferred
      // in firefox.
      const dimensions = JSON.parse(
        JSON.stringify(visualizerRef.current.getBoundingClientRect())
      );

      await canvasProxy(
        transfer(
          {
            canvas,
            message: VISUALIZER_MESSAGES.INIT,
            dimensions,
            range,
            mode
          },
          [canvas]
        )
      );
    })();
  }, []);
github transcend-io / penumbra / src / API.ts View on Github external
await new EncryptionChannel().then(async (thread: PenumbraWorkerAPI) => {
      /**
       * PenumbraWorkerAPI.encrypt calls require('./encrypt').encrypt()
       * from the worker thread and starts reading the input stream from
       * [remoteWritableStream.writable]
       */
      thread.encrypt(
        options,
        ids,
        sizes,
        transfer(readablePorts, readablePorts),
        transfer(writablePorts, writablePorts),
      );
    });
    // encryption jobs submitted and still processing
github transcend-io / penumbra / src / API.ts View on Github external
await new EncryptionChannel().then(async (thread: PenumbraWorkerAPI) => {
      /**
       * PenumbraWorkerAPI.encrypt calls require('./encrypt').encrypt()
       * from the worker thread and starts reading the input stream from
       * [remoteWritableStream.writable]
       */
      thread.encrypt(
        options,
        ids,
        sizes,
        transfer(readablePorts, readablePorts),
        transfer(writablePorts, writablePorts),
      );
    });
    // encryption jobs submitted and still processing
github transcend-io / penumbra / src / API.ts View on Github external
await new DecryptionChannel().then(async (thread: PenumbraWorkerAPI) => {
      /**
       * PenumbraWorkerAPI.encrypt calls require('./encrypt').encrypt()
       * from the worker thread and starts reading the input stream from
       * [remoteWritableStream.writable]
       */
      thread.decrypt(
        options,
        ids,
        sizes,
        transfer(readablePorts, readablePorts),
        transfer(writablePorts, writablePorts),
      );
    });
    // encryption jobs submitted and still processing
github transcend-io / penumbra / src / API.ts View on Github external
new DecryptionChannel().then(async (thread: PenumbraWorkerAPI) => {
      await thread.get(transfer(writablePorts, writablePorts), resources);
    });
    return readables as PenumbraFile[];
github transcend-io / penumbra / src / penumbra.worker.js View on Github external
resources.map(async (resource) => {
        if (!('url' in resource)) {
          throw new Error(
            'PenumbraDecryptionWorker.getBuffers(): RemoteResource missing URL',
          );
        }
        const buffer = await new Response(
          await fetchAndDecrypt(resource),
        ).arrayBuffer();
        return Comlink.transfer(buffer, buffer);
      }),
    );
github ritz078 / raaga / utils / isOffscreenCanvasSupported.ts View on Github external
export async function checkSupportFor2dOffscreenCanvas() {
  const canvas = document.createElement("canvas");
  try {
    const _canvas: any = canvas.transferControlToOffscreen();
    return await testProxy(transfer(_canvas, [_canvas]));
  } catch (e) {
    return OFFSCREEN_2D_CANVAS_SUPPORT.NOT_SUPPORTED;
  }
}
github lovasoa / mandelbrot / src / mandelbrot.js View on Github external
export function mandelbrot_pixels(point, zoom, size) {
    const maxIter = PALETTE_SIZE - 1;
    const pxs = new Uint8ClampedArray(size.x * size.y * 4);
    const ratio_x = 1 / zoom;
    const ratio_y = 1 / zoom;
    for (let i = 0; i < pxs.length; i += 4) {
        let idx = i / 4 | 0;
        let x = idx % size.x;
        let y = idx / size.x | 0;
        let px = point.x + x * ratio_x;
        let py = point.y + y * ratio_y;
        let n = mandelbrot(px, py, maxIter);
        n = (n * 4) % palette.length;
        pxs.set(palette.subarray(n, n + 4), i);
    }
    return Comlink.transfer(pxs, [pxs.buffer]);
}

comlink

Comlink makes WebWorkers enjoyable

Apache-2.0
Latest version published 15 days ago

Package Health Score

92 / 100
Full package analysis

Similar packages