0.1.1 • Published 6 years ago

js-asynctask v0.1.1

Weekly downloads
1
License
ISC
Repository
github
Last release
6 years ago

js-asynctask

js中 执行异步任务

安装

 npm i js-asynctask --save

使用

const asyncTask = require('js-asynctask');

const middleWares = [];

middleWares.push(async function (context, next) {
  console.log('task-1');
  context.count++;
  await next();
});

middleWares.push(async function (context, next) {
  console.log('task-2');
  context.count++;
  await next();
});

middleWares.push(async function (context, next) {
  console.log('task-3');
  context.count++;
  await next();
});

const context = {
  count: 0,
};

asyncTask(middleWares, context).then(() => {
  console.log('finished', context.count);
});