Skip to content

m(icro)queue is a lightweight es6+ library that exports an asynchronous function queue with adjustable concurrency.

License

Notifications You must be signed in to change notification settings

ivoputzer/m.queue

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

46 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

m.queue

m(icro)queue is a lightweight es6+ library that exports an asynchronous function queue with adjustable concurrency.

travis dependencies coverage status linter

node version license minzip downloads

.async

creates a queue object with the specified concurrency. tasks added to the queue are processed in parallel (up to the concurrency limit). if all workers are in progress, the task is queued until one becomes available. once a worker completes a task, that task's callback is called.

const {async} = require('m.queue')

const queue = async(function worker (arg0, arg1, callback) {
  if (err) {
    callback(err)
    return
  }
  callback(null, arg0, arg1)
}, 10)

.sequence

creates a queue object. tasks added to the queue are processed sequentially. while the worker is executing tasks will be queued. once a worker completes a task, that task's callback is called.

const {sequence} = require('m.queue')

const queue = sequence(function worker (arg0, arg1, callback) {
  if (err) {
    callback(err)
    return
  }
  callback(null, arg0, arg1)
})

queue.resume()

resumes worker execution

queue.pause()

pauses worker execution

queue.drain([callback])

sets concurrency to infinite and notifies when idle

queue.unshift([...args, callback]])

unshifts task to queue

queue.push([..args, callback])

pushes task to queue

queue.length

inherited from array, returns the queue length

queue.shift()

inherited from array

queue.pop()

inherited from array

About

m(icro)queue is a lightweight es6+ library that exports an asynchronous function queue with adjustable concurrency.

Resources

License

Code of conduct

Stars

Watchers

Forks

Packages

No packages published