queue-for-js

1.0.2 • Public • Published

Queue for js

代交向队列中添加数据,队列按顺序依次执行回调

Use

const Queue = require('queue-for-js')

function printItem(item, done) {
  const t = Math.random() * 5000
  setTimeout(() => {
    console.log(item)
    done()
  }, t)
}

const q = new Queue({autoStart: true, limit: 10, callback: printItem})

q.push(1,2,3,4,5,6,7,8,9,10,11,12,13,14)


q = new Queue({limit: 10, callback: printItem})

q.push(1,2,3,4,5,6,7,8,9,10,11,12,13,14)


config

autoStart

default true 实例化对像后是否直接执行队列

limit

default 10 队列处理上线

callback params: item【队列项】 done【队列项处理结束回调-标记这项处理完毕,可以排出队列空间】

callback 处理队列项的回调

Instance methods

push()

  • 类似 array push, 可以添加数据列,也可以添加单项

isEmpty()

  • 判断队列是否为空

run()

  • 执行队列

stop()

  • 暂停队列

Readme

Keywords

Package Sidebar

Install

npm i queue-for-js

Weekly Downloads

0

Version

1.0.2

License

ISC

Unpacked Size

3.84 kB

Total Files

3

Last publish

Collaborators

  • yuqiongqianlimu