microlink
Comlink Alternative
features
- easily pass functions to worker threads
- built with JSON-RPC 2.0
- zero run-time dependencies
- batching
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';
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
batching
import { expose } from "microlink";
expose(methods, {
batch_size: 10,
batch_wait: 100,
})
debugging
const options = { debug_level: 10 };
expose(methods, options);
wrap(worker, options)