2.0.0 • Published 11 months ago

linka v2.0.0

Weekly downloads
6
License
ISC
Repository
-
Last release
11 months ago

linka codecov GitHub license build

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.

:boom: It's works on both Node and Browser. :muscle: Zero dependency

This module exposes three module definitions:

  • CommonJS: dist/linka.js
  • ESModule: dist/linka.mjs
  • UMD: dist/linka.min.js

Install

$ npm install --save linka

Example Linka Implementation for WebWorker

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}`);

License

MIT © Pathik Devani

2.0.0

11 months ago

1.0.1-beta

4 years ago

1.0.0

4 years ago

0.0.1

4 years ago

0.0.0

4 years ago