How to use the comlink.transferHandlers 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 / transferHandlers / penumbra-events.ts View on Github external
/* eslint-disable @typescript-eslint/no-explicit-any */
import * as Comlink from 'comlink';

/** TODO: abstract this into a re-usable event registration & serialization helper */

Comlink.transferHandlers.set('penumbra-progress', {
  /**
   * Checks if object is a penumbra-progress event
   *
   * @param object Object being passed through Comlink.transfer()
   * @returns true if the object is a penumbra-progress CustomEvent
   */
  canHandle(object: any) {
    return object instanceof CustomEvent && object.type === 'penumbra-progress';
  },
  /**
   * Serialize penumbra-progress event down to just ProgressDetails
   *
   * @param object Reference to the penumbra-progress CustomEvent
   * @returns [Clonables (structured-clone-compatible objects), [Transferables]]
   */
  serialize(object: any) {
github transcend-io / penumbra / src / transferHandlers / penumbra-events.ts View on Github external
*/
  serialize(object: any) {
    return [object.detail, []];
  },
  /**
   * Re-create CustomEvent for re-dispatch in current context
   *
   * @param detail Structured-clone data from serialize()
   * @returns A re-created penumbra-encryption-complete CustomEvent
   */
  deserialize(detail: any) {
    return new CustomEvent('penumbra-encryption-complete', { detail });
  },
});

Comlink.transferHandlers.set('penumbra-error', {
  /**
   * Checks if object is a penumbra-progress event
   *
   * @param object Object being passed through Comlink.transfer()
   * @returns true if the object is a penumbra-progress CustomEvent
   */
  canHandle(object: any) {
    return object instanceof CustomEvent && object.type === 'penumbra-error';
  },
  /**
   * Serialize penumbra-progress event down to just ProgressDetails
   *
   * @param object Reference to the penumbra-progress CustomEvent
   * @returns [Clonables (structured-clone-compatible objects), [Transferables]]
   */
  serialize(object: any) {

comlink

Comlink makes WebWorkers enjoyable

Apache-2.0
Latest version published 5 days ago

Package Health Score

82 / 100
Full package analysis

Similar packages