alias for `new Promise` plus useful features like compose


Keywords
Promise, short-hand, promisify, async, await, compose, polyfill, alias
License
MIT
Install
npm install prs@3.5.0

Documentation

Build Status

prs

alias for new Promise

Install

$ npm install --save prs
# or
$ yarn add prs

API

Table of Contents

prs

returns a new Promise

Parameters

  • resolver
  • null function (resolve, [reject]) => ..

Examples

prs(resolve => {
	load(url, resolve);
}).then(...)

compose

creates a Promise of a none-promise function you can also use: promisify() prsfy() and prs.fy() or prs.ensure() or prs.compose()

Parameters

Examples

const fn = value => value;
const promise = prs.compose(fn);
const value = await promise('check');

resolve

returns Promise.resolve you can also use: res() and prs.res() prs.resolve

Parameters

  • null any *

reject

returns Promise.reject you can also use: rej() and prs.rej() prs.reject()

Parameters

  • null any *

all

returns Promise.all

Parameters

  • null any *

Usage

const prs = require('prs');

const resolver = (resolve, reject) => {
  setTimeout(()=>{
    resolve('foo');
  }, 1000);
};

// Alias for new Promise
prs(resolver)
  .then((val) => {
    console.log(val);
    // => foo
  });

// await
async function(){
  const value = await prs(resolver)
}

// Alias for Promise.resolve
prs.resolve()
  .then()...

const value = await prs.resolve('check');

// or
prs.res()
  .then()...


// Alias for Promise.all
prs.all([prs,prs...])

// compose
const func = value => value;
const promise = prs.compose(func);
const value = await promise('check');
t.is(value, 'check');

License

MIT © Sönke Kluth