0.0.1 • Published 4 months ago

p-batcher v0.0.1

Weekly downloads
-
License
MIT
Repository
-
Last release
4 months ago

p-batcher

npm version npm downloads

A promise batcher, collect promises and run them in batch.

Install

npm i p-batcher

Usage

import { createPBatch } from "p-batcher"

const api = createPBatch((keys: number[]) => {
  console.log("batching", keys)
  return keys.map((k) => `res-${k}`)
}, {
  maxBatchSize: 3,
})

const res = await Promise.all([
  api(1),
  api(2),
  api(3),
  api(4),
  api(5),
])

console.log(res)

/*
output:
batching [ 1, 2, 3 ]
batching [ 4, 5 ]
[ 'res-1', 'res-2', 'res-3', 'res-4', 'res-5' ]

*/

License

MIT © vaakian

0.0.1

4 months ago

0.0.1-alpha.2

5 months ago

0.0.1-alpha.1

5 months ago

0.0.1-alpha.0

5 months ago