promised-util

0.2.0 • Public • Published

promised-util

NPM Version Build Status

  • 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

Readme

Keywords

Package Sidebar

Install

npm i promised-util

Weekly Downloads

1

Version

0.2.0

License

MIT

Unpacked Size

6.12 kB

Total Files

7

Last publish

Collaborators

  • zf