https://github.com/mhio/pinky
Pinky promise helpers for node
https://github.com/mhio/pinky
promises typescript
Last synced: 2 months ago
JSON representation
Pinky promise helpers for node
- Host: GitHub
- URL: https://github.com/mhio/pinky
- Owner: mhio
- License: mit
- Created: 2021-02-07T22:49:41.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2024-02-18T05:21:32.000Z (over 1 year ago)
- Last Synced: 2025-01-30T12:28:32.102Z (4 months ago)
- Topics: promises, typescript
- Language: JavaScript
- Homepage:
- Size: 368 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
pinky promise
-------------[github.com/mhio/pinky](https://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.`
map an async function across an iterable`mapSeries(iterator, asyncFn) ⇒ Promise.`
map an async function in series across an iterable`mapConcurrent(iterator_in, asyncFn, concurrent_num) ⇒ Promise.`
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](https://mhio.github.io/pinky/modules.html)
```
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