# proxyworker

> Simple wrapper for proxying api requests from mt to worker

Latest version **2.1.2** (published 2018-04-12) · MPL-2.0 license · 0 weekly downloads

## Install

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

## Health

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

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.1.2 |
| Published | 2018-04-12 |
| First published | 2015-04-13 |
| Weekly downloads | 0 |
| License | MPL-2.0 |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 301.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Gareth |
| Maintainers | gaye |

## Links

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

## Recent versions

- 2.1.2 (latest) — 2018-04-12
- 2.1.1 — 2018-04-12
- 2.1.0 — 2018-04-11
- 2.0.1 — 2018-04-10
- 2.0.0 — 2018-04-10
- 1.4.0 — 2016-01-13
- 1.3.5 — 2015-10-03
- 1.3.4 — 2015-10-03
- 1.3.3 — 2015-07-28
- 1.3.2 — 2015-07-06
- 1.3.1 — 2015-07-06
- 1.3.0 — 2015-07-03
- 1.2.1 — 2015-07-03
- 1.2.0 — 2015-04-15
- 1.1.0 — 2015-04-14
- … 2 more at https://npm.io/package/proxyworker/versions

## README

proxyworker
===========

[![CircleCI](https://circleci.com/gh/scidock/proxyworker.svg?style=svg)](https://circleci.com/gh/scidock/proxyworker)

Lightweight utility to proxy api requests from main thread to web worker.
Run the tests in your browser [here](https://scidock.github.io/proxyworker/test)!

### Usage

```js
// Main thread
const {ProxyWorker} = require('proxyworker');

const worker = new ProxyWorker(new Worker('./path/to/worker.js'));

// Call 'echo' method on worker with some arguments.
// This returns a promise that will resolve with the worker api response.
worker.callWithArgs('echo', ['a', 'b', 'c', 1, 2, 3]);

// Subscribe to worker event.
worker.subscribe('breakfast', breakfast => {
  // breakfast => ['green', 'eggs', 'and', 'tofu']
});
```

```js
// worker.js
const {emit, proxy} = require('proxyworker');

proxy({
  methods: {
    echo: function() {
      let result = Array.prototype.slice.call(arguments);
      return Promise.resolve(result);
    }
  },

  events: [
    'breakfast',
  ]
});

// Time for breakfast?
setInterval(function() {
  emit('breakfast', [
    'green',
    'eggs',
    'and',
    'tofu',
  ]);
}, 24 * 60 * 60 * 1000);
```

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