JanMakur / node-threads

A JavaScript Module which helps you in running concurrent process loops inside a single thread

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

node-threads

a Simple Module to Create Threads

Commonjs Example Modernjs Example TypeScript Example

CommonJS Example

const { createContinuousThreads } = require('./commonjs.cjs');
const { createThreads } = require('./commonjs.cjs');
const { createThread } = require('./commonjs.cjs');
//Create Thread
createThread(() => {
    setTimeout(function() {
        console.log(`new thread`);
    } , 5000)
})
createThreads(5 , () => {
    console.log('multiple threads');
})
createContinuousThreads(6 , () => {
    console.log(`6 threads will run at a time :D after they end new thread will be created`);
})

ModernJS Example

import { createContinuousThreads } from './modernjs.mjs'
import { createThreads } from './modernjs.mjs'
import { createThread } from './modernjs.mjs'
//Create Thread
createThread(() => {
    setTimeout(function() {
        console.log(`new thread`);
    } , 5000)
})
createThreads(5 , () => {
    console.log('multiple threads');
})
createContinuousThreads(6 , () => {
    console.log(`6 threads will run at a time :D after they end new thread will be created`);
})

TypeScript Example

import { createContinuousThreads } from '../typescript.ts';
import { createThreads } from '../typescript.ts';
import { createThread } from '../typescript.ts';
//Create Thread
createThread(() => {
    setTimeout(function() {
        console.log(`new thread`);
    } , 5000)
});
createThreads(5 , () => {
    console.log('multiple threads');
});
createContinuousThreads(6 , () => {
    console.log(`6 threads will run at a time :D after they end new thread will be created`);
});

About

A JavaScript Module which helps you in running concurrent process loops inside a single thread


Languages

Language:JavaScript 67.4%Language:TypeScript 32.6%