@mhio/pinky
TypeScript icon, indicating that this package has built-in type declarations

0.8.3 • Public • Published

pinky promise

github.com/mhio/pinky

yarn add @mhio/pinky
npm i @mhio/pinky

delay(ms) ⇒ Promise
delay for ms

delayFrom(ts, ms) ⇒ Promise
Delay from a timestamp for milliseconds

delayTo(ts) ⇒ Promise
Delay until a timestamp milliseconds

map(iterator, asyncFn) ⇒ Promise.<Array>
map an async function across an iterable

mapSeries(iterator, asyncFn) ⇒ Promise.<Array>
map an async function in series across an iterable

mapConcurrent(iterator_in, asyncFn, concurrent_num) ⇒ Promise.<Array>
Use n workers to resolve a function across an iterable. (via .mapSeries) Resulting array is in worker order, then work started order, so doesn't match initial order.

firstWithoutError(iterable) ⇒ Promise
Run a bunch of promises, if the first fails return the next until all promises have been checked. All promises start resolving immediately.

firstInSeriesWithoutError(iterable) ⇒ Promise
Run a bunch of promises in series, if the one fails move onto the next.

allProps(obj) ⇒ object
Resolve all promises in an object

outerSettle()
Create a promise and return the promise,resolve and reject Allows you to resolve/reject the promise out of the promise scope

waitFor(timeout_ms, condition_fn, options) ⇒ object
Wait until a timestamp for some condition function to become truthey. Can be an async or standard function

API docco

const { delay, mapSeries } = require('@mhio/pinky')
import { delay, mapSeries } from '@mhio/pinky'

async function go(){
  const waits = [ 60, 10, 50, 5, 35, 19 ]
  const res = await mapSeries(waits, async (ms) => {
    console.log('wait ms', ms)
    await delay(ms)
    return ms
  })
}

go().catch(console.error)

mhio 2022

Package Sidebar

Install

npm i @mhio/pinky

Weekly Downloads

1

Version

0.8.3

License

MIT

Unpacked Size

111 kB

Total Files

27

Last publish

Collaborators

  • mhio