Skip to content

Latest commit

 

History

History
39 lines (32 loc) · 1.14 KB

README.md

File metadata and controls

39 lines (32 loc) · 1.14 KB

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