Skip to content

Commit

Permalink
change lib name
Browse files Browse the repository at this point in the history
  • Loading branch information
mdwekat committed Sep 28, 2023
1 parent 3cdf008 commit 7bc5d3b
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 22 deletions.
42 changes: 21 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
> :warning: **Warning:** This is an experimental package and may undergo significant changes. Please use with caution and feel free to report any issues or suggestions.
# ThreadIt
# NodeSwarm

[![npm version](https://badge.fury.io/js/threadit.svg)](https://badge.fury.io/js/threadit)
[![Known Vulnerabilities](https://snyk.io/test/github/mdwekat/threadit/badge.svg)](https://snyk.io/test/github/mdwekat/threadit)
[![npm version](https://badge.fury.io/js/nodeswarm.svg)](https://badge.fury.io/js/nodeswarm)
[![Known Vulnerabilities](https://snyk.io/test/github/mdwekat/nodeswarm/badge.svg)](https://snyk.io/test/github/mdwekat/nodeswarm)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)

> Efficiently manage and utilize worker threads in Node.js.
ThreadIt is a lightweight, easy-to-use library designed to simplify the process of creating, managing, and utilizing
worker threads in Node.js, enabling developers to easily leverage multi-core processing power for CPU-bound tasks.
`NodeSwarm` is a lightweight, easy-to-use library designed to simplify the process of creating, managing, and utilizing
worker threads in Node.js, enabling developers to easily leverage multicore processing power for CPU-bound tasks.

### Motivation and Features
`ThreadIt` was developed to simplify multithreading in Node.js, reducing the hassle and distraction from extensive boilerplate required by `worker_threads`. The library enables direct execution of any function using threads, removing the need for separate files, especially beneficial for TypeScript users, all within a clean and intuitive API.
`NodeSwarm` was developed to simplify multithreading in Node.js, reducing the hassle and distraction from extensive boilerplate required by `worker_threads`. The library enables direct execution of any function using threads, removing the need for separate files, especially beneficial for TypeScript users, all within a clean and intuitive API.

## Features
- **Efficiency:** Offers optimal performance and scalability through simplified multithreading and efficient management of CPU-bound tasks.
Expand All @@ -22,23 +22,23 @@ worker threads in Node.js, enabling developers to easily leverage multi-core pro
- **Flexibility:** Provides adjustable configurations to suit various needs.

## Installation
Install ThreadIt using npm:
Install NodeSwarm using npm:

```shell
npm install threadit
npm install nodeswarm
```

Or with yarn:

```shell
yarn add threadit
yarn add nodeswarm
```

## Quick Start
Here's a simple example of how to use ThreadIt to run a task in a separate thread:
Here's a simple example of how to use NodeSwarm to run a task in a separate thread:

```typescript
const { ThreadPool } = require('threadit');
const { ThreadPool } = require('nodeswarm');

const pool = new ThreadPool();

Expand All @@ -58,11 +58,11 @@ main();

## Fibonacci Example

Let's use the famous Fibonacci function to compare running tasks with normal Promises and with the ThreadIt ThreadPool. Fibonacci is a CPU-bound task which makes it a good candidate to showcase the benefits of multithreading.
Let's use the famous Fibonacci function to compare running tasks with normal Promises and with the NodeSwarm ThreadPool. Fibonacci is a CPU-bound task which makes it a good candidate to showcase the benefits of multithreading.

```typescript
// Import your thread pool
import { ThreadPool } from 'threadit'; // Adjust the import path as necessary
import { ThreadPool } from 'nodeswarm'; // Adjust the import path as necessary

const pool = new ThreadPool();

Expand All @@ -88,7 +88,7 @@ console.timeEnd('fib thread');

## Limitations

`ThreadIt` offers a streamlined approach to multithreading in Node.js but has its constraints:
`NodeSwarm` offers a streamlined approach to multithreading in Node.js but has its constraints:

1. **Independent Execution:** Threads run separately, and despite parallel execution, each context remains single-threaded.
2. **Data Sharing:** Data between threads is copied, not shared. `SharedArrayBuffer` support is planned for the future.
Expand All @@ -98,24 +98,24 @@ console.timeEnd('fib thread');
6. **Incompatibility with Classes:** The library may not handle classes as expected.
7. **Experimental Status:** Potential for bugs or API changes. Use cautiously in production.

Ensure `ThreadIt` aligns with your requirements before integrating it into projects.
Ensure `NodeSwarm` aligns with your requirements before integrating it into projects.


## Security Consideration: Use of Eval

`ThreadIt` utilizes `eval()` internally to dynamically execute functions in worker threads. While this offers flexibility and ease of use, it also necessitates caution:
`NodeSwarm` utilizes `eval()` internally to dynamically execute functions in worker threads. While this offers flexibility and ease of use, it also necessitates caution:

- **Do not use `ThreadIt` to run untrusted or user-provided code.** Doing so can expose your application to significant security risks, including arbitrary code execution.
- **Use exclusively with your own, well-reviewed code.** Ensure that the code being run with `ThreadIt` is secure and has been thoroughly reviewed to avoid potential security vulnerabilities.
- **Do not use `NodeSwarm` to run untrusted or user-provided code.** Doing so can expose your application to significant security risks, including arbitrary code execution.
- **Use exclusively with your own, well-reviewed code.** Ensure that the code being run with `NodeSwarm` is secure and has been thoroughly reviewed to avoid potential security vulnerabilities.

By adhering strictly to these guidelines, you can mitigate risks associated with the use of `eval()` and safely enjoy the benefits of `ThreadIt`.
By adhering strictly to these guidelines, you can mitigate risks associated with the use of `eval()` and safely enjoy the benefits of `NodeSwarm`.


## API
### ThreadPool
`new ThreadPool([config])`

Creates a new thread pool. Optionally, you can provide a config object to specify the pool size.
Create a new thread pool. Optionally, you can provide a config object to specify the pool size.

`thread(fn: Function, ...args: any[]): Promise<any>`

Expand All @@ -130,4 +130,4 @@ Gracefully closes all worker threads after completing all ongoing jobs.
Immediately terminates all worker threads.

## License
ThreadIt is MIT licensed.
NodeSwarm is MIT licensed.
7 changes: 6 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
{
"name": "threadit",
"name": "nodeswarm",
"version": "0.0.1",
"description": "Lightweight library for managing worker threads and parallel execution of tasks in Node.js.",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"repository": "https://github.com/mdwekat/nodeswarm.git",
"bugs": {
"url": "https://github.com/mdwekat/nodeswarm/issues"
},
"homepage": "https://github.com/mdwekat/nodeswarm#readme",
"scripts": {
"build": "rimraf dist && tsc",
"pretest": "rimraf test_tmp && tsc -p tsconfig.worker.json",
Expand Down

0 comments on commit 7bc5d3b

Please sign in to comment.