priority-promise-queue
TypeScript icon, indicating that this package has built-in type declarations

0.0.2 • Public • Published

priority-promise-queue

what is this

Let the asynchronous queue respond to the results in the order in which it was requested.

use examples

import PriorityPromiseQueue from 'priority-promise-queue'

const ppq = new PriorityPromiseQueue()

ppq.add(new Promise((resolve: any) => resolve('1')))
ppq.add(new Promise((resolve: any) => setTimeout(() => resolve('2'), 100)))
ppq.add(new Promise((resolve: any) => setTimeout(() => resolve('3'), 10)))
ppq.add(new Promise((resolve: any) => resolve('4')))
ppq.add([
  new Promise((resolve: any) => setTimeout(() => resolve('5'), 300)),
  new Promise((resolve: any) => resolve('6')),
])

ppq.call((result: any[], done: boolean) => {
  result.forEach((item: any[]) => {
    const [err, data] = item;
    if (!err && data) {
      // do something...
    }
  })

  if (done) {
    // end...
  }
})

// Results of the
// [[null, '1']], false
// [[null, '2'],[null, '3'],[null, '4']], false
// [[null, '5'],[null, '5']], true

API

function description parameter
add Add Promise to the queue Promise
call Handle the response in the Promise column of the team [[error, data]] The returned promise array, each item is an array containing error and data, error is null by default, if error exists, it means that the promise request reported an error

Build a development environment

1. Fork project, then clone to local.
git clone git@github.com:txs1992/priority-promise-queue.git

2. Installation dependencies (make sure your computer has Node.js installed)
yarn install

3. run the project
yarn serve

License

MIT

/priority-promise-queue/

    Package Sidebar

    Install

    npm i priority-promise-queue

    Weekly Downloads

    4

    Version

    0.0.2

    License

    MIT

    Unpacked Size

    36.9 kB

    Total Files

    23

    Last publish

    Collaborators

    • _mt