🚀 Socket Launch Week Day 5:Introducing Repository Access Permissions and Custom Roles.Learn more
Sign In

work-pool

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

work-pool

NodeJS fast work pool

latest
Source
npmnpm
Version
1.1.1
Version published
Weekly downloads
3
-25%
Maintainers
1
Weekly downloads
 
Created
Source

work-pool

work-pool은 동시에 여러 작업을 처리하는 데에 유리합니다.

npm install work-pool
const Pool = require('./Pool'); // 모듈 불러오기

const P1 = Pool( 5 ); // 최대 동시 처리 갯수(5개)

P1.work(function (next) {
    // 실행할 코드 입력.

    
    next(); // 실행이 끝난 후 next 호출
})

example

example code

const Pool = require('./Pool');

const P1 = Pool(3);

for (let i = 1 ; i <= 11; i ++) {
    P1.work(function(next){
        setTimeout(function(){
            console.log( new Date().toLocaleTimeString(), i);
            next();
        }, 1000);
    })
}
P1.finish(function () {
    console.log('FINISH');
});

실행결과

n-ui-MacBookPro:work-pool n$ node example.js 
5:40:18 PM 1
5:40:18 PM 2
5:40:18 PM 3
5:40:19 PM 4
5:40:19 PM 5
5:40:19 PM 6
5:40:20 PM 7
5:40:20 PM 8
5:40:20 PM 9
5:40:21 PM 10
5:40:21 PM 11
FINISH
  • P1.work( )로 동시에 실행한 11개의 함수들이 pool의 수에 따라 순차적으로 실행되었습니다.

FAQs

Package last updated on 22 Jul 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts