async-funnel
v1.0.1
Published
async funnel
Downloads
5
Maintainers
Readme
node-async-funnel
说明
网址: https://gitee.com/linuxmail/node-async-funnel
npm i async-funnel
用于
一个一个的执行: 支持Promise的函数
并行个数可配置
用法
const funnel = require("async-funnel").asyncFunnel
let funnel = new asyncFunnel.asyncFunnel({ parallel: 2 })
let funnel = new asyncFunnel.asyncFunnel() // parallel == 1
await funnel.run(async () => {
await do_sth()
})
例子
// const funnel = require("async-funnel").asyncFunnel
const asyncFunnel = require("../src/")
async function do_job(funnel, sn) {
console.log("函数开始执行: ", sn)
await funnel.run(async () => {
await asyncFunnel.sleep(1000)
console.log(sn, (new Date()))
})
}
function test(parallel) {
let funnel = new asyncFunnel.asyncFunnel({ parallel: parallel })
// if (parallel == 1) {
// let funnel = asyncFunnel()
// }
for (i = 0; i < 100; i++) {
do_job(funnel, i)
}
}
test(2)