1.0.0 • Published 7 years ago

potato-promise v1.0.0

Weekly downloads
5
License
WTFPL
Repository
github
Last release
7 years ago

potato-promise

NPM Version WTFPL Travis NPM Downloads

Super tiny, dependency-free wrapper to make promises lazy, i.e. sit there like a potato until .then() is invoked.

Assumes native promises, or at least Promise on the global scope (global or window).

Installation

$ npm i -S potato-promise

Usage

const Potato = require('potato-promise')

const p = new Potato((resolve) => {
  console.log(3)
  resolve()
})

console.log(1)

setTimeout(() => {
  console.log(2)
  p.then(() => {}).catch(() => {})
}, 1000)

// > 1
// ...after 1 second...
// > 2
// > 3

Note: I'm only using new here for familiar semantics; this is actually a factory function. The following would also work...

Promise.lazy = require('potato-promise')

const p = Promise.lazy((resolve) => ...)