Skip to content

Latest commit

History

4 Commits

Folders and files

NameName
Last commit message
Last commit date

Repository files navigation

nanoqueue

A processing queue with workload limit

Installation

npm i nanoqueue

Usage

constNanoQueue=require('nanoqueue')letsum=0constqueue=newNanoQueue(15,{// Process enqueue items, invoke `done' when doneprocess: (n,done)=>{setTimeout(()=>{sum+=nconsole.log(`Current progress: ${Math.floor(queue.progress*100)}, ${queue.remaining} items remaining`)done()},50)},// Will be invoked every time queue.remaining reaches 0oncomplete: ()=>{console.log('All done, current sum:',sum)}})for(leti=0;i<100;i++){queue.push(i)}

class NanoQueue

Properties

  • ro{Number} remaining Amount of items that have not yet finished processing
  • ro{Number} progress Value between 0 and 1

Constructor

new NanoQueue(nSlots, handlers)

Arguments

  • {Number} nSlots Number of active work slots.
  • {Object} handlers
    • {Function} process (item, done) Invoked for enqueued item once a slot is free
    • optional{Function} oncomplete () Invoked whenever remaining becomes 0

Description

Creates a new NanoQueue instance with specified amount of work-slots. The process handler is required to be implemented and once invoked it must in turn invoke the done callback to let the queue continue.

Function: push

queue.push(item)

Description

Enqueues itemfor processing

Function: reset

queue.reset()

Description

Resets processed/enqueued counters back to zero

License

This software is released under GNU LGPL 3.0 or later

About

A processing queue with workload limits

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages