callink
v1.0.1
Published
A Worker → Main communication library inspired by Comlink
Maintainers
Readme
Callink
Callink is a TypeScript library inspired by Comlink, designed to simplify communication from Web Workers to the main thread.
Features
- Worker → Main – If Comlink simplifies calling Workers from the main thread,
Callinksimplifies calling the main thread from Workers. - Simple usage – Call main-thread functions directly from a Worker, just like local functions.
- Transferable support – Supports high-performance transfer of
ArrayBuffer,OffscreenCanvas, and other transferable objects.
Install
npm install callinkExample
main.ts
import { Callink } from "callink";
const obj = {
counter: 0,
inc() {
this.counter++;
},
};
const worker = new Worker("worker.js");
Callink.provide(worker, api);worker.ts
import { Callink } from "callink";
async function init() {
const main = Callink.connect();
alert(`Counter: ${await main.counter}`);
await main.inc();
alert(`Counter: ${await main.counter}`);
}
init();Transferable
const data = new Uint8Array([1, 2, 3, 4, 5]);
await main.send(Callink.transfer(data, [data.buffer]));License
MIT License © 2025 oyc0401
