Skip to content

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

Notifications You must be signed in to change notification settings

JanMakur/node-threads

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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`);
});