1.0.0 • Published 3 years ago

@jswork/next-async-queue v1.0.0

Weekly downloads
1
License
MIT
Repository
-
Last release
3 years ago

next-async-queue

Async queue for next.

version license size download

installation

npm install -S @jswork/next-async-queue

apis

apiparamsdescription
runitemsRun a list of async functions
repeatfn, countGet a repeat functions
wrapfn,fnWrap an list of functions to runnable

status

statusnamecodedescription
LOADload1Status when task is running
DONEdone0Status when all task has done

usage

import NxAsyncQueue from '@jswork/next-async-queue';

var fn1 = function(next){
  setTimeout(function(){
    console.log(123,'1s');
    next({ result: 1});
  },1000);
};

var fn2 = function(next){
  setTimeout(function(){
    console.log(456,'2s');
    next({ result: 2});
  },1000);
};

var fn3 = function(next){
  setTimeout(function(){
    console.log(789,'3s');
    next({ result: 3});
  },1000);
};

NxAsyncQueue.run(fn1, fn2, fn3).then((res) => {
  console.log(res);
});

// results:
// 123 1s
// 456 2s
// 789 3s
// [ { result: 1 }, { result: 2 }, { result: 3 } ]

license

Code released under the MIT license.