Git Product home page Git Product logo

promise-concurrency's Introduction

Promise 任务并发控制器

Build

需求描述

  1. PromiseConcurrencyController 构造函数接受一个 number 类型的参数,作为并发数量。
  2. 实例上有一个 run 方法,接受一组返回 Promise 的函数,多次调用 run 方法时传入的函数将以传入的顺序执行,同一个 PromiseConcurrencyController 实例不管调用多少次 run 方法,传入的任务都需要按照构造函数中定义的并发数量运行
  3. run 方法返回 ConcurrencyResult 实例,它实现了 AsyncIterator<T, void, void> 接口,也就是说它可以用 for ... await 语句进行迭代。ConcurrencyResult 类我们已经帮你实现,并且有相应的测试代码: concurrency-result.spec.ts, 你可以在当前目录下执行 yarn test 查看测试结果。
  4. stop 方法可以暂停控制器,这个方法返回一个 Promise, 等待当前正在执行的所有 Promise resolve/reject 之后返回的 Promiseresolve,该方法返回的 Promise 只有可能被 resolve 不会被 reject。如果已经被暂停则直接 resolve 返回的 Promise
  5. resume 方法可以继续控制器的执行,用于控制器被 stop 之后恢复执行。
  6. 可以通过实例上的 activeCountpendingCount 获得正在运行的任务个数以及等待个数。

评判标准

  • 完成需求
  • 补充 PromiseConcurrencyController 的单元测试
  • 工程化 (CI/CD/Lint 等)
  • 代码风格

promise-concurrency's People

Contributors

lnwu avatar brooooooklyn avatar

Watchers

James Cloos avatar  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.