2.0.1 • Published 5 years ago

run-queue v2.0.1

Weekly downloads
10,724,254
License
ISC
Repository
github
Last release
5 years ago

run-queue

A promise based, dynamic priority queue runner, with concurrency limiting.

const RunQueue = require('run-queue')

const queue = new RunQueue({
  maxConcurrency: 1
})

queue.add(1, example, [-1])
for (let ii = 0; ii < 5; ++ii) {
  queue.add(0, example, [ii])
}
const finished = []
queue.run().then(
  console.log(finished)
})

function example (num, next) {
  setTimeout(() => {
    finished.push(num)
    next()
  }, 5 - Math.abs(num))
}

would output

[ 0, 1, 2, 3, 4, -1 ]

If you bump concurrency to 2, then you get:

[ 1, 0, 3, 2, 4, -1 ]

The concurrency means that they don't finish in order, because some take longer than others. Each priority level must finish entirely before the next priority level is run. See PRIORITIES below. This is even true if concurrency is set high enough that all of the regular queue can execute at once, for instance, with maxConcurrency: 10:

[ 4, 3, 2, 1, 0, -1 ]

API

const queue = new RunQueue(options)

Create a new queue. Options may contain:

  • maxConcurrency - (Default: 1) The maximum number of jobs to execute at once.
  • Promise - (Default: global.Promise) The promise implementation to use.

queue.add (prio, fn, args)

Add a new job to the end of the queue at priority prio that will run fn with args. If fn is async then it should return a Promise.

queue.run ()

Start running the job queue. Returns a Promise that resolves when either all the jobs are complete or a job ends in error (throws or returns a rejected promise). If a job ended in error then this Promise will be rejected with that error and no further queue running will be done.

PRIORITIES

Priorities are any integer value >= 0.

Lowest is executed first.

Priorities essentially represent distinct job queues. All jobs in a queue must complete before the next highest priority job queue is executed.

This means that if you have two queues, 0 and 1 then ALL jobs in 0 must complete before ANY execute in 1. If you add new 0 level jobs while 1 level jobs are running then it will switch back processing the 0 queue and won't execute any more 1 jobs till all of the new 0 jobs complete.

move-concurrentlycopy-concurrentlyvuedragdropuploadimagespopsmart-common-authkilli8n-react-native-fast-image@cashremit/cr-streamline-iconsbb-chat@frxf/frxf@fundefund/funde_ckgql_din_mod@l1nyanm1ng/react-picture-viewerjs4cytoscape@saaspe/components@everything-registry/sub-chunk-2692l2forlernalitepie-datepicker-gabehelp-widgethot-zone-vuehubot-budajamuskalimjesusdemomyui5librarychenmyui5librarymobong-search-dropdownmiracle-webpack-tree-shakingmyreuselibrarym2m-chartjs-plugin-crosshairmiguelcostero-ng2-toastynois-react-toast@southcn/ckeditor5-build-inline@udooku/react-image-comparison-slider@timonbandit/crittr@tillschweneker/ckeditor5-build-strapi-wysiwyg-markdown@tonysusi/vapid@vitali_shcherbina/styled-lib@shivarajapple/first-library@openpolitica/matomo-next@oriduk/ckeditor5-rebuild-musicanote@oriduk/ckeditor5-rebuild-oriduk@skeetboothppq/component-library@rbc-public/react-selectable-fast@react-18-pdf/root@stansaal/ckeditor5-custom-build@sackmanson/quill-image-uploader@safely-project/safely-ts@seculum/vue-dev-clonea_react_reflux_demo@zh0st/evm-chains@zebracompany/f_editor@arielapaula/components@arielapaula/test@artiso-solutions/vue-html-to-paperappcharge-checkoutappcharge-checkout-reactjs-sdkap-vue-captcha@beldore/react-otp-inputbonatto@cube-design/react@blkmarketco/components-librarycampus-carosellocampus1campus2campus3campus4caropcarop2carop3carop4carosello-campus-opacitacarosello-tribuscarosello-tribus-2case-gg-editorcar-cmp-2@carhoo/widget-dealers@simstudio/htmldiffguruwayguruway.jsqa_hddprova-2-caroselloprova-cmpprova-cpm-2prova-cpm-3prova-cpm-4qyx-hmtldiffreact-form-component-libraryreact-misc-toolboxparvan_componentsparvan_reactjs_componentsreact-redux-demo1react-picky-with-clearreact-otp-input-uptdsequelcomponentvformlmqverify-img-codevue-compmentvue-dev-clonetinymce-plugin-toytextfield-sampletestapavue-button-test1
2.0.1

5 years ago

2.0.0

6 years ago

1.0.3

7 years ago

1.0.2

7 years ago

1.0.1

7 years ago

1.0.0

7 years ago