# microlink

> Comlink Alternative. Built with JSON-RPC.

Latest version **0.3.0** (published 2023-12-03) · CC0-1.0 license · 0 weekly downloads

## Install

```sh
npm install microlink
pnpm add microlink
yarn add microlink
bun add microlink
```

## Health

**Score 20/100 (F)** — status: abandoned.

Positive: esm support; no vulnerabilities.

Warnings: low downloads; no types; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.3.0 |
| Published | 2023-12-03 |
| First published | 2023-03-13 |
| Weekly downloads | 0 |
| License | CC0-1.0 |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 60.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Daniel J. Dufour |
| Maintainers | danieljdufour |
| Keywords | comlink, jsonrpc, message, rpc, threads, web, worker |

## Links

- npm: https://www.npmjs.com/package/microlink
- Repository: https://github.com/DanielJDufour/microlink
- Homepage: https://github.com/DanielJDufour/microlink#readme
- Issues: https://github.com/DanielJDufour/microlink/issues
- npm.io page: https://npm.io/package/microlink

## Alternatives

- [@opentelemetry/exporter-zipkin](https://npm.io/package/@opentelemetry/exporter-zipkin.md) — 14.8M weekly downloads
- [pusher-js](https://npm.io/package/pusher-js.md) — 2.0M weekly downloads
- [browserify](https://npm.io/package/browserify.md) — 1.7M weekly downloads
- [sqs-consumer](https://npm.io/package/sqs-consumer.md) — 1.7M weekly downloads
- [@sanity/eventsource](https://npm.io/package/@sanity/eventsource.md) — 930.8K weekly downloads

## Recent versions

- 0.3.0 (latest) — 2023-12-03
- 0.2.0 — 2023-12-03
- 0.1.2 — 2023-11-30
- 0.1.1 — 2023-08-07
- 0.1.0 — 2023-08-05
- 0.0.2 — 2023-03-19
- 0.0.1 — 2023-03-13

## README

# microlink
> Comlink Alternative

## features
- easily pass functions to worker threads
- built with [JSON-RPC 2.0](https://www.jsonrpc.org/specification)
- zero run-time dependencies
- await promise in another thread
- batching

## usage
#### inside worker.js
```js
import { expose } from 'microlink';

expose({
  run: (func, args) => func(...args),
  halve: n => n / 2,
});
```

#### inside main.js
```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
#### batching
```js
import { expose } from "microlink";

expose(methods, {
  batch_size: 10, // how many requests per batch should be sent up to the main thread
  batch_wait: 100, // wait up to 100ms for batch to be filled before sent
})
```

#### debugging
```js
// pass an options object to expose or wrap
const options = { debug_level: 10 };

expose(methods, options);
wrap(worker, options)
```

---
_Source: https://npm.io/package/microlink · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
