1.1.0 • Published 1 year ago

node-threadify v1.1.0

Weekly downloads
-
License
GPL-3.0
Repository
github
Last release
1 year ago

📂 | Installation

npm install node-threadify
# (or)
yarn add node-threadify

📜 | Setup

const { Threading } = require("node-threadify"); //Importing client
const threads = new Threading({ threads: 5 }); //Amount of threads

✍ | Examples

import { Threading } from "node-threadify";

const wait = (ms) => new Promise((resolve) => setTimeout(resolve, ms));

(async () => {
  let threads = new Threading({ threads: 5 }); //numbers of workers which will work at a time

  let number_of_times_we_wave_to_run = 10; //total number of times we have to run

  for (let i = 0; i < number_of_times_we_wave_to_run; i++) {
    threads.insert(main, i); //(function, ...arguments)
  }

  threads.run();
})();

async function main(index) {
  console.log(`Starting with session: ${index}.`);

  //...code

  await wait(50000 * Math.random()); //assuming our function can take random time to resolve

  //after all stuff done
  console.log(`Completed with session: ${index}.`);
}

All of our examples and activites are in examples folder. If you have any other problems/questions, you can open up a issue.

1.1.1

1 year ago

1.1.0

1 year ago

1.0.0

1 year ago