function-threads
Advanced tools
Comparing version 1.0.0 to 1.0.1
{ | ||
"name": "function-threads", | ||
"version": "1.0.0", | ||
"version": "1.0.1", | ||
"description": "Multi-threading library for Node.js which allows run functions in thread.", | ||
@@ -22,3 +22,3 @@ "keywords": [ | ||
"lint_examples": "NODE_ENV=development eslint examples --fix", | ||
"test": "nyc mocha spec/** && node --experimental-worker spec/integration", | ||
"test": "nyc node --experimental-worker node_modules/mocha/bin/_mocha test/**", | ||
"coverage": "nyc report --reporter=text-lcov | npx coveralls" | ||
@@ -25,0 +25,0 @@ }, |
@@ -5,9 +5,33 @@ [![Build Status](https://travis-ci.org/nairihar/function-threads.svg?branch=master)](https://travis-ci.org/nairihar/function-threads) | ||
[![Maintainability](https://api.codeclimate.com/v1/badges/58a6979fd059a021b05e/maintainability)](https://codeclimate.com/github/nairihar/function-threads/maintainability) | ||
[![npm version](https://badge.fury.io/js/function-threads.svg)](https://www.npmjs.com/package/function-threads) | ||
# Function Threads | ||
Additional layer for Node.js "worker_threads" module. | ||
Additional layer for Node.js's "worker_threads" module. | ||
Library provides "run" function, which takes an callback as argument, and runs it in a thread. It returns a promise, inside callback you can return promise or plain value(i.e. object, string and etc...). | ||
Library provides `run` function, which takes an callback as argument and runs it in a thread. It returns a promise, inside callback you can return promise or plain value(i.e. object, string and etc...). | ||
### Example | ||
## Installation | ||
Using npm: | ||
```shell | ||
$ npm i --save function-threads | ||
``` | ||
Using yarn: | ||
```shell | ||
$ yarn add function-threads | ||
``` | ||
## Example | ||
Make sure you're using Node.js >= v10.5.0 | ||
And always use `--experimental-worker` flag when you run project, because under the hood has been implemented [worker-threads](https://nodejs.org/api/worker_threads.html) which is in Experimental mode. | ||
```shall | ||
$ node --experimental-worker index.js | ||
``` | ||
Example [_basic/index.js_](https://github.com/nairihar/function-threads/blob/master/examples/basic/index.js): | ||
```javascript | ||
@@ -24,1 +48,11 @@ const Thread = require('function-threads'); | ||
``` | ||
```shell | ||
$ node --experimental-worker index.js | ||
``` | ||
### All examples: | ||
- [Basic](https://github.com/nairihar/function-threads/tree/master/examples/basic) | ||
- [Run thread with custom data](https://github.com/nairihar/function-threads/blob/master/examples/run_thread_with_custom_data/index.js) | ||
- [Async thread](https://github.com/nairihar/function-threads/blob/master/examples/async_thread/index.js) | ||
- [Error handling](https://github.com/nairihar/function-threads/blob/master/examples/error_in_thread/index.js) |
8821
152
57