Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

p-lazy

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

p-lazy

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

  • 3.0.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
92K
decreased by-16.44%
Maintainers
1
Weekly downloads
 
Created
Source

p-lazy Build Status

Create a lazy promise that defers execution until it's awaited or when .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 p-lazy

Usage

const PLazy = require('p-lazy');

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

// `someHeavyOperation` is not yet called

(async () => {
	await doSomethingFun;
	// `someHeavyOperation` is called
	console.log(await lazyPromise);
})();

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.

License

MIT © Sindre Sorhus

Keywords

FAQs

Package last updated on 03 Apr 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc