promised-util
v0.2.0
Published
utils to work with promises
Downloads
2
Readme
promised-util
- timeout: set timeout on a promise
- postpone: postpone a promise
- sleep: create a promise that will resolve in given time
- pipe: pipe a promise through a series of functions
- tee: observe a promise without altering it
usage
postpone
const {postpone} = require('promised-util')
Promise.resolve('val').then(postpone(1000)).then(result =>
console.log(`${result} one second later`))
sleep
const {sleep} = require('promised-util')
async () => {
await sleep(1000)
}
timeout
const {timeout, TimeoutError, sleep} = require('promised-util')
timeout(100, sleep(200)).catch(err =>
console.log(err instanceof TimeoutError))
pipe
const {pipe} = require('promised-util')
pipe(Promsie.resolve([1, 2]), xs => xs.map(x => x * x), xs => xs.filter(x => x > 1))
pipe(Promsie.reject('err'), xs => xs.map(x => x * x), xs => xs.filter(x => x > 1))
fulfilled/rejected
const {fulfilled, rejected} = require('promised-util')
await fulfilled(Promise.resolve(null)) // true
await rejected(Promise.reject(null)) // true