Nutella Peanut-Butter Marshmallow
Share your code. npm Orgs help your team discover, share, and reuse code. Create a free org »

p-lazy

1.0.0 • Public • Published

p-lazy Build Status

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.

Install

$ npm install --save p-lazy

Usage

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);
});

API

new PLazy(executor)

Same as the Promise constructor. PLazy is a subclass of Promise.

PLazy.from(fn)

Create a PLazy promise from a promise-returning or async function.

Related

License

MIT © Sindre Sorhus

install

npm i p-lazy

Downloadsweekly downloads

185,958

version

1.0.0

license

MIT

homepage

github.com

repository

Gitgithub

last publish

collaborators

  • avatar
Report a vulnerability