# inline-worker

> utility to create a universal WebWorker from a function

Latest version **1.1.0** (published 2016-06-14) · MIT license · 0 weekly downloads

## Install

```sh
npm install inline-worker
pnpm add inline-worker
yarn add inline-worker
bun add inline-worker
```

## 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 | 1.1.0 |
| Published | 2016-06-14 |
| First published | 2015-03-16 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Nao Yonamine |
| Maintainers | mohayonao |
| Keywords | worker |

## Links

- npm: https://www.npmjs.com/package/inline-worker
- Repository: https://github.com/mohayonao/inline-worker
- Homepage: https://github.com/mohayonao/inline-worker/
- Issues: https://github.com/mohayonao/inline-worker/issues
- npm.io page: https://npm.io/package/inline-worker

## Alternatives

- [cron](https://npm.io/package/cron.md) — 4.9M weekly downloads
- [@vercel/queue](https://npm.io/package/@vercel/queue.md) — 731.6K weekly downloads
- [create-sonicjs](https://npm.io/package/create-sonicjs.md) — 1.6K weekly downloads
- [@exellix/jobs-api](https://npm.io/package/@exellix/jobs-api.md) — 941 weekly downloads
- [@forwardimpact/libskill](https://npm.io/package/@forwardimpact/libskill.md) — 575 weekly downloads

## Recent versions

- 1.1.0 (latest) — 2016-06-14
- 1.0.0 — 2015-12-21
- 0.1.0 — 2015-03-16

## README

# inline-worker
[![Build Status](http://img.shields.io/travis/mohayonao/inline-worker.svg?style=flat-square)](https://travis-ci.org/mohayonao/inline-worker)
[![NPM Version](http://img.shields.io/npm/v/inline-worker.svg?style=flat-square)](https://www.npmjs.org/package/inline-worker)
[![License](http://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square)](http://mohayonao.mit-license.org/)

> JavaScript utility to create a universal WebWorker from a function

## Installation

```
$ npm install inline-worker
```

## API
### InlineWorker

- `constructor(func: function, [ self: object ]): Worker | InlineWorker`

## Example

```js
const InlineWorker = require("inline-worker");

let self = {};
let worker = new InlineWorker(function(self) {
  self.onmessage = function(e) {
    postMessage(self.bark(e.data)); // (2) hello!!
  };

  // worker internal function
  self.bark = function(msg) {
    return msg + "!!";
  };
}, self);

worker.onmessage = function(e) {
  console.log(e.data + "!!"); // (3) hello!!!!
};

worker.postMessage("hello"); // (1)
```

What is `worker` instance?

```js
if (global.window === global) {
  assert(worker instanceof Worker); // in the borwser
} else {
  assert(worker instanceof InlineWorker); // in the node.js
}
```

You can test worker internal functions via `self`.

```js
assert(self.bark("bye") === "bye!!");
```

## License
MIT

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