Giter Club home page Giter Club logo

async-task-queue's Introduction

为 nodejs 实现了一个简易的异步任务队列管理

异步方可以在任何时候添加到队列中,队列会按照添加的顺序依次执行。

注意:方法必须返回一个 Promise

This is a single async task queue manager for nodejs

This is a single async task queue manager for nodejs, you can add async functions to the TaskQueue at any time. Functions will run one by one.

Example

function f1() {
  return new Promise((resolve, reject) => {
    setTimeout(() => {
      console.log("f1 done");
      try {
        a(); // error
        resolve();
      } catch (e) {
        reject(e);
      }
    }, 1000);
  });
}
function f2() {
  return new Promise(resolve => {
    setTimeout(() => {
      console.log("f2 done");
      resolve();
    }, 700);
  });
}
function f3() {
  return new Promise(resolve => {
    setTimeout(() => {
      console.log("f3 done");
      resolve();
    }, 500);
  });
}

const AsyncTaskQueue = require("@wolfx/async-task-queue");
const asyncTaskQueue = new AsyncTaskQueue();

asyncTaskQueue
  .add(f1)
  .add(f2)
  .add(f3);

async-task-queue's People

Contributors

furrywolfx 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.