1.0.0 • Published 8 years ago
potato-promise v1.0.0
potato-promise
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) => ...)
1.0.0
8 years ago