A tiny Promise based low-level communication for two way stream
Linka is low level communication module. It allows promise based communication on both ends. Using linka you can write wrapper in your application for specific socket, WebSocket, iframe stream.
💥 It's works on both Node and Browser. 💪 Zero dependency
This module exposes three module definitions:
- CommonJS:
dist/linka.js
- ESModule:
dist/linka.mjs
- UMD:
dist/linka.min.js
$ npm install --save linka
UI side where we create worker instance
import { Linka } from 'linka';
const worker = new Worker('worker.js');
const linka = new Linka(
(callback) => { worker.addEventListener('message', (e) => { callback(e.data); }); },
(data) => { worker.postMessage(data); },
{ timeout: 1000 * 10 },
);
// call worker to get some data
linka
.request('name', { fname: 'foo', lname: 'bar' })
.then((data) => { console.log(data); }); // foo bar
worker.js
import { Linka } from 'linka';
const self = {};
const linka = new Linka(
(callback) => { self.addEventListener('message', (e) => { callback(e.data); }); },
(data) => { self.postMessage(data); },
{ timeout: 1000 * 10 },
);
// bind event
self.bind('name', async (e) => `${e.fname}-${e.lname}`);
MIT © Pathik Devani