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');advanced usage
debugging
// pass an options object to expose or wrap
const options = { debug_level: 10 };
expose(methods, options);
wrap(worker, options)