How to use the comlink.expose 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 wasmerio / wasmer-js / packages / wasm-terminal / src / workers / process.worker.ts View on Github external
// Expoprt process as a worker
import * as Comlink from "comlink";
import Process from "../process/process";

Comlink.expose(Process);
github transcend-io / penumbra / src / zip.penumbra.worker.js View on Github external
//     }
  //     // add file to output
  //   });

  //   localStream.pipeTo(remoteStream);
  // }

  /**
   * Forward progress events to main thread
   */
  async setup(handler) {
    onProgress.handler = handler;
  }
}

Comlink.expose(PenumbraZipWorker);
github OpenNeuroOrg / openneuro / packages / openneuro-app / src / scripts / workers / validate.worker.js View on Github external
validate.BIDS(files, options, (issues, summary) =>
      resolve({ issues, summary }),
    )
  })

async function runValidator(files, options, cb) {
  let error, output
  try {
    output = await asyncValidateBIDS(files, options)
  } catch (err) {
    error = err
  }
  cb({ error, output })
}

Comlink.expose(runValidator)

// satisfies linters
export default null
github casual-simulation / aux / src / aux-vm / vm / AuxChannel.worker.ts View on Github external
listenForChannel().then(port => {
    console.log('[AuxChannel.worker] Got port, exposing API');
    expose(AuxImpl, port);
});
github fluid-notion / fluid-outliner / pwa-shell / src / models / Repository.ts View on Github external
import { LocalPersistencePlugin } from "../helpers/LocalPersistencePlugin"
import * as Comlink from "comlink"
import { Repository } from "../../../core/models/Repository"

Repository.plugins.push(LocalPersistencePlugin)

Comlink.expose(Repository, self)
github ritz078 / raaga / workers / loadInstrument.worker.ts View on Github external
};

async function loadInstruments(instrumentIds: number[], drums?: boolean) {
  const promises = instrumentIds.map(instrumentId => {
    const { value } = getInstrumentById(instrumentId.toString(10));

    return loadSoundFont(value);
  });

  const drumPromise = drums ? loadSoundFont(null, true) : undefined;

  await Promise.all([...promises, ...(drumPromise ? [drumPromise] : [])]);
  return midiFontData;
}

Comlink.expose(loadInstruments);
github ritz078 / raaga / workers / midiParse.worker.ts View on Github external
if (isNotMidi(isString(filePath) ? filePath : name)) {
    const text = await res.text();
    vrv.loadData(text);
    const base64Midi = vrv.renderToMIDI();

    arrayBuffer = base64ToArrayBuffer(base64Midi);
  } else {
    arrayBuffer = await res.arrayBuffer();
  }

  const midi = new MidiParser(arrayBuffer, name);
  return midi.parse();
};

Comlink.expose(parseMidi);
github Sketch-sh / nit / client / src / vendor / rtop.worker.js View on Github external
importScripts("/berror.js");
importScripts("/reason.js");

const Comlink = require("comlink");

const obj = {
  execute: evaluator.execute,
  reset: evaluator.reset,
  reasonSyntax: evaluator.reasonSyntax,
  mlSyntax: evaluator.mlSyntax,
  parseError: berror.parse,
};

Comlink.expose(obj, self);
github GoogleChromeLabs / squoosh / src / codecs / processor-worker / index.ts View on Github external
'../webp/decoder');
  return decode(data);
}

const exports = {
  mozjpegEncode,
  quantize,
  rotate,
  resize,
  optiPngEncode,
  webpEncode,
  webpDecode,
};
export type ProcessorWorkerApi = typeof exports;

expose(exports, self);
github GoogleChromeLabs / squoosh / src / components / App / client-api.ts View on Github external
export function exposeAPI(app: App) {
  self.parent.postMessage({ type: 'READY', version: MAJOR_VERSION }, '*');
  self.addEventListener('message', (event: MessageEvent) => {
    if (event.data !== 'READY?') {
      return;
    }
    event.stopImmediatePropagation();
    self.parent.postMessage({ type: 'READY', version: MAJOR_VERSION } as ReadyMessage, '*');
  });
  expose(new API(app), self.parent);
}

comlink

Comlink makes WebWorkers enjoyable

Apache-2.0
Latest version published 2 days ago

Package Health Score

85 / 100
Full package analysis

Similar packages