vlad 6f123ff03e 18.07 | 6 лет назад | |
---|---|---|
.. | ||
index.js | 6 лет назад | |
license | 6 лет назад | |
package.json | 6 лет назад | |
readme.md | 6 лет назад |
Create a lazy promise that defers execution until
.then()
or.catch()
is called
Useful if you're doing some heavy operations and would like to only do it when the promise is actually used.
$ npm install --save p-lazy
const PLazy = require('p-lazy');
const lazyPromise = new PLazy(resolve => {
someHeavyOperation(resolve);
});
// `someHeavyOperation` is not yet called
doSomethingFun.then(() => {
// `someHeavyOperation` is called
lazyPromise.then(console.log);
});
Same as the Promise
constructor. PLazy
is a subclass of Promise
.
Create a PLazy
promise from a promise-returning or async function.
MIT © Sindre Sorhus