JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 4094
  • Score
    100M100P100Q120820F
  • License CC0-1.0

Comlink Alternative. Built with JSON-RPC.

Package Exports

  • microlink
  • microlink/index.js

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (microlink) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

microlink

Comlink Alternative

features

  • easily pass function to another thread
  • built with JSON-RPC 2.0
  • zero run-time dependencies

usage

inside worker.js

import { expose } from 'microlink';

expose({
  run: (func, args) => func(...args),
  halve: n => n / 2,
});

inside main.js

import { wrap } from 'microlink';
// or, import wrap from 'microlink/wrap';

const worker = new Worker("worker.js");
const obj = await wrap(worker);

await obj.halve(10);
5

const count_elements = selector => document.querySelectorAll(selector).length;
await obj.run(count_elements, 'div');