Skip to content
/ queuefy Public

Wrapper to make any async handler act like a single thread with a queue

License

Notifications You must be signed in to change notification settings

qiwi/queuefy

Repository files navigation

queuefy

CI Maintainability Test Coverage npm (tag)

Wrapper to make any async handler act like a single thread with a queue.

Install

yarn add queuefy
npm i queuefy

Usage

import {queuefy} from 'queuefy'

let count = 0
const target = (param: number) => new Promise(resolve =>
  setTimeout(() => {
    count++
    resolve(count + param)
  }, Math.random() * 100),
)
const fn = queuefy(target)
const [r0, r1, r2, r3, r4] = await Promise.all([fn(4), fn(3), fn(2), fn(1), fn(0)])

// r0 is 5
// r1 is 5
// r2 is 5
// ... 

Alternatives

License

MIT