Clean up project (#91)
authorShinigami <chrissi92@hotmail.de>
Tue, 9 Feb 2021 17:34:14 +0000 (18:34 +0100)
committerGitHub <noreply@github.com>
Tue, 9 Feb 2021 17:34:14 +0000 (18:34 +0100)
.eslintrc.js
.prettierignore
CONTRIBUTING.md
LICENSE
README.md [moved from README.MD with 51% similarity]
package-lock.json
package.json

index 8f902bd228e5b3a81ede40194c699f73ef121b66..6c710303838f3cfbcbb05084ea11b739872fbe61 100644 (file)
@@ -38,7 +38,7 @@ module.exports = {
       'warn',
       {
         ignoreMemberSort: true,
-        memberSyntaxSortOrder: ['none', 'all', 'single', 'multiple']
+        ignoreDeclarationSort: true
       }
     ]
   },
index 76106cb929b3e15c3036ca9e2e0b7a16806df6ea..e40d57b1e25c381fbadae36741e29467be34e9a1 100644 (file)
@@ -1,2 +1,3 @@
 .nyc_output/
+coverage/
 lib/
index c57e879c470025a798698ca1944e03b54d75b5ae..d41ad6e0d70de479a3ff0002f000d89218f840af 100644 (file)
@@ -1,28 +1,28 @@
-<h2 id="contribute">How to contribute</h2>
+## How to contribute
 
-[![JavaScript Style Guide](https://cdn.rawgit.com/standard/standard/master/badge.svg)](https://github.com/standard/standard)<br>
-This repo use standard js style , please use it if you want to contribute <br>
-Take tasks from todo list, develop a new feature or fix a bug and do a pull request.<br>
-Another thing that you can do to contribute is to build something on top of ring-election and link ring-election to your project <br>
+[![JavaScript Style Guide](https://cdn.rawgit.com/standard/standard/master/badge.svg)](https://github.com/standard/standard)  
+This repo use standard js style, please use it if you want to contribute  
+Take tasks from todo list, develop a new feature or fix a bug and do a pull request.  
+Another thing that you can do to contribute is to build something on top of ring-election and link ring-election to your project
 
-Please ask your PR to be merged on <strong>master</strong> branch . <br>
+Please ask your PR to be merged on **master** branch.
 
-<strong>How to run tests</strong><br>
+**How to run tests**
 
-<strong>Unit tests </strong> <br>
+**Unit tests**
 
 ```bash
   npm run test
 ```
 
-<strong> How to check if your new code is standard style </strong><br>
+**How to check if your new code is standard style**
 
 ```bash
   npm run lint
 ```
 
-<strong>How to lint and format (with prettier) your code</strong><br>
+**How to lint and format (with prettier) your code**
 
 ```bash
-  npm run lint:fix
+  npm run format && npm run lint:fix
 ```
diff --git a/LICENSE b/LICENSE
index 7ab0bbd0fc7c5453f9f23cf43eb9756dafa7f9b7..306f35e618ddfc58cc95301ae16ebfaa72e5a107 100644 (file)
--- a/LICENSE
+++ b/LICENSE
@@ -1,6 +1,6 @@
 MIT License
 
-Copyright (c) 2019-2020 Alessandro Pio Ardizio
+Copyright (c) 2019-2021 Alessandro Pio Ardizio
 
 Permission is hereby granted, free of charge, to any person obtaining a copy
 of this software and associated documentation files (the "Software"), to deal
similarity index 51%
rename from README.MD
rename to README.md
index 465ab8d9a236c24871e8743bbab13bb578136ec2..17c46101e753e251b51257bc230b0ef73841bf49 100644 (file)
--- a/README.MD
+++ b/README.md
@@ -1,53 +1,58 @@
 # Node Thread Pool :arrow_double_up: :on:
+
 [![JavaScript Style Guide](https://img.shields.io/badge/code_style-standard-brightgreen.svg)](https://standardjs.com)
 [![Dependabot](https://badgen.net/dependabot/dependabot/dependabot-core/?icon=dependabot)](https://badgen.net/dependabot/dependabot/dependabot-core/?icon=dependabot)
 [![npm w](https://img.shields.io/npm/dw/poolifier)](https://www.npmjs.com/package/poolifier)
 [![Actions Status](https://github.com/pioardi/node-pool/workflows/NodeCI/badge.svg)](https://github.com/pioardi/node-pool/actions)
-[![Coverage Status](https://coveralls.io/repos/github/pioardi/poolifier/badge.svg?branch=master)](https://coveralls.io/github/pioardi/poolifier?branch=master)[![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat-square)](http://makeapullrequest.com)
-[![NODEP](https://img.shields.io/static/v1?label=dependencies&message=no%20dependencies&color=brightgreen
-)](https://img.shields.io/static/v1?label=dependencies&message=no%20dependencies&color=brightgreen
-)
+[![Coverage Status](https://coveralls.io/repos/github/pioardi/poolifier/badge.svg?branch=master)](https://coveralls.io/github/pioardi/poolifier?branch=master)
+[![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat-square)](http://makeapullrequest.com)
+[![NODEP](https://img.shields.io/static/v1?label=dependencies&message=no%20dependencies&color=brightgreen)](https://img.shields.io/static/v1?label=dependencies&message=no%20dependencies&color=brightgreen)
 [![Gitter](https://badges.gitter.im/poolifier/community.svg)](https://gitter.im/poolifier/community?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge)
 
-<h2>Why Poolifier? </h2>
-Poolifier is used to perform heavy CPU bound tasks on nodejs servers, it implements thread pools ( yes, more thread pool implementations, so you can choose which one fit better for you ) using <a href="https://nodejs.org/api/worker_threads.html#worker_threads_worker_threads">worker-threads </a>.<br>
-With poolifier you can improve your <strong>performance</strong> and resolve problems related to the event loop.<br>
-Moreover you can execute your CPU tasks using an API designed to improve the <strong>developer experience</strong>.
+## Why Poolifier?
 
+Poolifier is used to perform heavy CPU bound tasks on nodejs servers, it implements thread pools (yes, more thread pool implementations, so you can choose which one fit better for you) using [worker-threads](https://nodejs.org/api/worker_threads.html#worker_threads_worker_threads).  
+With poolifier you can improve your **performance** and resolve problems related to the event loop.  
+Moreover you can execute your CPU tasks using an API designed to improve the **developer experience**.
 
+## Contents
 
-<h2>Contents </h2>
 <h3 align="center">
+  <a href="#overview">Overview</a>
+  <span> · </span>
   <a href="#installation">Installation</a>
   <span> · </span>
   <a href="#usage">Usage</a>
   <span> · </span>
+  <a href="#node-versions">  Node versions</a>
+  <span> · </span>
   <a href="#api">API</a>
   <span> · </span>
-  <a href="#cyp">Choose a pool</a>
+  <a href="#choose-your-pool">Choose your pool</a>
   <span> · </span>
   <a href="#contribute">Contribute</a>
   <span> · </span>
-  <a href="#Team">Team</a>
-  <span> · </span>
-  <a href="#nv">Compatibility</a>
+  <a href="#team">Team</a>
   <span> · </span>
   <a href="#license">License</a>
 </h3>
 
-<h2> Overview </h2>
-Node pool contains two <a href="https://nodejs.org/api/worker_threads.html#worker_threads_worker_threads">worker-threads </a> pool implementations , you don' t have to deal with worker-threads complexity. <br>
-The first implementation is a static thread pool , with a defined number of threads that are started at creation time and will be reused.<br>
-The second implementation is a dynamic thread pool with a number of threads started at creation time ( these threads will be always active and reused) and other threads created when the load will increase ( with an upper limit, these threads will be reused when active ), the new created threads will be stopped after a configurable period of inactivity. <br>
-You have to implement your worker extending the ThreadWorker class<br>
-<h2 id="installation">Installation</h2>
+## Overview
 
-```
+Node pool contains two [worker-threads](https://nodejs.org/api/worker_threads.html#worker_threads_worker_threads) pool implementations, you don't have to deal with worker-threads complexity.  
+The first implementation is a static thread pool, with a defined number of threads that are started at creation time and will be reused.  
+The second implementation is a dynamic thread pool with a number of threads started at creation time (these threads will be always active and reused) and other threads created when the load will increase (with an upper limit, these threads will be reused when active), the new created threads will be stopped after a configurable period of inactivity.  
+You have to implement your worker extending the ThreadWorker class
+
+## Installation
+
+```shell
 npm install poolifier --save
 ```
-<h2 id="usage">Usage</h2>
 
-You can implement a worker in a simple way , extending the class ThreadWorker :
+## Usage
+
+You can implement a worker in a simple way, extending the class ThreadWorker:
 
 ```js
 'use strict'
@@ -59,7 +64,10 @@ function yourFunction (data) {
   return { ok: 1 }
 }
 
-module.exports = new ThreadWorker(yourFunction, { maxInactiveTime: 60000, async: false })
+module.exports = new ThreadWorker(yourFunction, {
+  maxInactiveTime: 60000,
+  async: false
+})
 ```
 
 Instantiate your pool based on your needed :
@@ -88,72 +96,81 @@ pool.execute({}).then(res => {
 
 ```
 
-<strong> See examples folder for more details( in particular if you want to use a pool for [multiple functions](./examples/multiFunctionExample.js) ).</strong>
-<strong>Now type script is also supported, find how to use it into the example folder </strong>
+**See examples folder for more details (in particular if you want to use a pool for [multiple functions](./examples/multiFunctionExample.js)).**
+**Now type script is also supported, find how to use it into the example folder**
 
-<h2 id="nv">Node versions</h2>
+## Node versions
 
-You can use node versions 12.x , 13.x, 14.x <br>
+You can use node versions 12.x, 13.x, 14.x
 
-<h2 id="api">API</h2>
+## API
 
 ### `pool = new FixedThreadPool(numThreads, filePath, opts)`
-`numThreads` (mandatory) Num of threads for this worker pool <br>
-`filePath` (mandatory) Path to a file with a worker implementation <br>
+
+`numThreads` (mandatory) Num of threads for this worker pool  
+`filePath` (mandatory) Path to a file with a worker implementation  
 `opts` (optional) An object with these properties :
+
 - `errorHandler` - A function that will listen for error event on each worker thread
 - `onlineHandler` - A function that will listen for online event on each worker thread
 - `exitHandler` - A function that will listen for exit event on each worker thread
-- `maxTasks` - This is just to avoid not useful warnings message, is used to set <a href="https://nodejs.org/dist/latest-v12.x/docs/api/events.html#events_emitter_setmaxlisteners_n">maxListeners</a> on event emitters ( workers are event emitters)
+- `maxTasks` - This is just to avoid not useful warnings message, is used to set [maxListeners](https://nodejs.org/dist/latest-v12.x/docs/api/events.html#events_emitter_setmaxlisteners_n) on event emitters (workers are event emitters)
 
 ### `pool = new DynamicThreadPool(min, max, filePath, opts)`
-`min` (mandatory) Same as FixedThreadPool numThreads , this number of threads will be always active <br>
-`max` (mandatory) Max number of workers that this pool can contain, the new created threads will die after a threshold ( default is 1 minute , you can override it in your worker implementation). <br>
-`filePath` (mandatory) Same as FixedThreadPool  <br>
-`opts` (optional) Same as FixedThreadPool <br>
+
+`min` (mandatory) Same as FixedThreadPool numThreads, this number of threads will be always active  
+`max` (mandatory) Max number of workers that this pool can contain, the new created threads will die after a threshold (default is 1 minute, you can override it in your worker implementation).  
+`filePath` (mandatory) Same as FixedThreadPool  
+`opts` (optional) Same as FixedThreadPool
 
 ### `pool.execute(data)`
-Execute method is available on both pool implementations ( return type : Promise): <br>
-`data` (mandatory) An object that you want to pass to your worker implementation <br>
+
+Execute method is available on both pool implementations (return type : Promise):  
+`data` (mandatory) An object that you want to pass to your worker implementation
 
 ### `pool.destroy()`
-Destroy method is available on both pool implementations.<br>
-This method will call the terminate method on each worker.
 
+Destroy method is available on both pool implementations.  
+This method will call the terminate method on each worker.
 
 ### `class YourWorker extends ThreadWorker`
-`fn` (mandatory) The function that you want to execute on the worker thread <br>
-`opts` (optional) An object with these properties :
+
+`fn` (mandatory) The function that you want to execute on the worker thread  
+`opts` (optional) An object with these properties:
+
 - `maxInactiveTime` - Max time to wait tasks to work on ( in ms) , after this period the new worker threads will die.
-- `async` - true/false , true if your function contains async pieces else false
+- `async` - true/false, true if your function contains async pieces else false
+
+## Choose your pool
 
-<h2 id="cyp">Choose your pool</h2>
-Performance is one of the main target of these thread pool implementations, we want to have a strong focus on this.<br>
+Performance is one of the main target of these thread pool implementations, we want to have a strong focus on this.  
 We already have a bench folder where you can find some comparisons.
-To choose your pool consider that with a FixedThreadPool or a DynamicThreadPool ( in this case is important the min parameter passed to the constructor) your application memory footprint will increase . <br>
-Increasing the memory footprint, your application will be ready to accept more CPU bound tasks, but during idle time your application will consume more memory. <br>
-One good choose from my point of view is to profile your application using Fixed/Dynamic thread pool , and to see your application metrics when you increase/decrease the num of threads. <br>
-For example you could keep the memory footprint low choosing a DynamicThreadPool with 5 threads, and allow to create new threads until 50/100 when needed, this is the advantage to use the DynamicThreadPool. <br>
-But in general , <strong>always profile your application </strong>
+To choose your pool consider that with a FixedThreadPool or a DynamicThreadPool (in this case is important the min parameter passed to the constructor) your application memory footprint will increase.  
+Increasing the memory footprint, your application will be ready to accept more CPU bound tasks, but during idle time your application will consume more memory.  
+One good choose from my point of view is to profile your application using Fixed/Dynamic thread pool, and to see your application metrics when you increase/decrease the num of threads.  
+For example you could keep the memory footprint low choosing a DynamicThreadPool with 5 threads, and allow to create new threads until 50/100 when needed, this is the advantage to use the DynamicThreadPool.  
+But in general, **always profile your application**
 
-<h2 id="contribute">Contribute</h2>
+## Contribute
 
-See guidelines [CONTRIBUTING](CONTRIBUTING.md) <br>
-Choose your task here <a href="https://github.com/pioardi/poolifier/projects/1"> 2.0.0</a>, propose an idea, a fix, an improvement. <br>
+See guidelines [CONTRIBUTING](CONTRIBUTING.md)  
+Choose your task here [2.0.0](https://github.com/pioardi/poolifier/projects/1), propose an idea, a fix, an improvement.
 
+## Team
 
-<h2 id="Team">Team</h2>
 <!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section -->
 <!-- prettier-ignore-start -->
 <!-- markdownlint-disable -->
 
 **Creator/Owner:**
-* [__Alessandro Pio Ardizio__](https://github.com/pioardi)
 
-***Contributors***
-* [__Shinigami92__](https://github.com/Shinigami92)
-* [__Jérôme Benoit__](https://github.com/jerome-benoit)
+- [**Alessandro Pio Ardizio**](https://github.com/pioardi)
+
+**_Contributors_**
+
+- [**Shinigami92**](https://github.com/Shinigami92)
+- [**Jérôme Benoit**](https://github.com/jerome-benoit)
 
-<h2 id="license">License</h2>
+## License
 
 [MIT](./LICENSE)
index e3e205ec54c92f77c03f5ae1a8a5989f8aee1000..9f0e752198430d77b1bc45cf6cd4d0c9c70eec4a 100644 (file)
       }
     },
     "eslint-plugin-prettierx": {
-      "version": "0.17.0",
-      "resolved": "https://registry.npmjs.org/eslint-plugin-prettierx/-/eslint-plugin-prettierx-0.17.0.tgz",
-      "integrity": "sha512-TsAyEIGvbcuJlnCwFjUqhQ2bMlPn1mX9JdmxvH8pPOVGBPQ6h4K7bVkH/6+TeVmpV41Rj/m5CXe0SU28OK46hg==",
+      "version": "0.17.1",
+      "resolved": "https://registry.npmjs.org/eslint-plugin-prettierx/-/eslint-plugin-prettierx-0.17.1.tgz",
+      "integrity": "sha512-UEcZtVY8+U8TwFcBFR7tKI+eBdYxU1iPbynUnCkofT/7e/msm981JY97gY0lI/GIIVG/xcIJST5PYzlTc/SwVw==",
       "dev": true,
       "requires": {
         "eslint-config-prettier": "~7.2.0",
index a30ae25f40d3ab173631481981481d49df39c75c..418bff365a3aeda145d9bf52bbcd81e5e4d39383 100644 (file)
@@ -6,9 +6,10 @@
   "scripts": {
     "build": "npm run build:clean && tsc",
     "build:clean": "rimraf lib",
-    "test": "npm run build && nyc mocha --exit --timeout 20000 tests/*test.js ",
-    "test:debug": "mocha --inspect-brk --exit tests/*test.js ",
+    "test": "npm run build && nyc mocha --exit --timeout 20000 tests/**/*.test.js",
+    "test:debug": "mocha --inspect-brk --exit tests/**/*.test.js",
     "coverage": "nyc report --reporter=text-lcov | coveralls",
+    "coverage:html": "nyc --reporter=html mocha --exit --timeout 20000 tests/**/*.test.js",
     "format": "prettier --loglevel silent --write .; prettierx --write .",
     "lint": "eslint .",
     "lint:fix": "eslint . --fix"
@@ -54,7 +55,7 @@
     "eslint-config-standard": "^16.0.2",
     "eslint-plugin-import": "^2.22.1",
     "eslint-plugin-node": "^11.1.0",
-    "eslint-plugin-prettierx": "^0.17.0",
+    "eslint-plugin-prettierx": "^0.17.1",
     "eslint-plugin-promise": "^4.2.1",
     "expect": "^26.6.2",
     "mocha": "^8.2.1",
@@ -67,6 +68,7 @@
     "typescript": "^4.1.3"
   },
   "engines": {
-    "node": ">=12.11.0"
+    "node": ">=12.11.0",
+    "npm": ">=6.0.0 <7"
   }
 }