A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/sindresorhus/p-lazy below:

sindresorhus/p-lazy: Create a lazy promise that defers execution until it's awaited or when .then() or .catch() is called

Create a lazy promise that defers execution until it's awaited or when .then(), or .catch(), or .finally() is called

Useful if you're doing some heavy operations and would like to only do it when the promise is actually used.

import PLazy from 'p-lazy';

const lazyPromise = new PLazy(resolve => {
	someHeavyOperation(resolve);
});

// `someHeavyOperation` is not yet called

await doSomethingFun;

// `someHeavyOperation` is called
console.log(await lazyPromise);

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

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

Create a PLazy promise that is resolved with the given value, or the promise passed as value.

Create a PLazy promise that is rejected with the given reason.


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4