GithubHelp home page GithubHelp logo

pool's Introduction

pool

threads pool for time-consuming operation 用于高内存消耗和耗时操作的线程调度池 适用于同时进行多个高内存消耗操作或互相之间会有冲突的异步操作 对传入的异步操作进行封顶截流操作,防止同时开启太多异步任务 需要es7,或使用babel

import

npm install --save @hudk/pool

usage

const Pool = require('@hudk/pool');
const p = new Pool(3);

funcions

Pool(poolNumber)

构造函数,初始化一个线程调度池

poolNumber | 能同时进行的最大线程数

add(async function)

向线程池中加入一个异步函数 该函数应当是执行真实耗时操作的函数的封装,千万不要传入一个Promise对象! 函数执行结果不会返回,若要返回,使用addSync

p.add(_ => { await f(); }); 

async addSync(functionList)

向线程中加入异步操作函数数组,数组内的函数全部完成后会将返回值放在数组中返回(类似Promise.all) 同add,数组中每个函数也是真实耗时操作的封装

const a = _ => {
  return new Promise(resolve) {
    // time-consuming operation or callback
    resolve();
  };
};

p.add([a, a, a]);

pool's People

Contributors

hudk114 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.