0.8.3 • Published 1 year ago

@mhio/pinky v0.8.3

Weekly downloads
166
License
MIT
Repository
-
Last release
1 year ago

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

0.8.3

1 year ago

0.8.1

2 years ago

0.8.0

2 years ago

0.8.2

2 years ago

0.7.0-1

3 years ago

0.7.1

2 years ago

0.7.0-2

3 years ago

0.7.0

3 years ago

0.6.4

3 years ago

0.6.2

3 years ago

0.6.0-1

3 years ago

0.6.1

3 years ago

0.6.0

3 years ago

0.5.0-1

4 years ago

0.5.0

4 years ago

0.4.1

4 years ago

0.4.2

4 years ago

0.3.0

4 years ago

0.2.2

4 years ago

0.2.1

4 years ago

0.2.0

4 years ago

0.1.1

4 years ago

0.1.1-0

4 years ago