Socket
Socket
Sign inDemoInstall

@ai-zen/lazy-promise

Package Overview
Dependencies
0
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @ai-zen/lazy-promise

LazyPromise is a TypeScript class that represents a lazy promise, which executes its executor function only when `then`, `catch`, or `finally` methods are called.


Version published
Weekly downloads
3
decreased by-25%
Maintainers
1
Install size
9.55 kB
Created
Weekly downloads
 

Readme

Source

LazyPromise

LazyPromise is a TypeScript class that represents a lazy promise, which executes its executor function only when then, catch, or finally methods are called.

Installation

Install LazyPromise using npm:

npm install @ai-zen/lazy-promise

Usage

Import LazyPromise class into your project:

import LazyPromise from "@ai-zen/lazy-promise";

Create a new instance of LazyPromise by passing an executor function:

const lazyPromise = new LazyPromise((resolve, reject) => {
  // Perform asynchronous operations and then call resolve or reject
});

Use the then method to attach fulfillment and rejection handlers:

lazyPromise.then(
  (value) => {
    // Handle the fulfilled promise
  },
  (reason) => {
    // Handle the rejected promise
  }
);

Use the catch method to attach a rejection handler:

lazyPromise.catch((reason) => {
  // Handle the rejected promise
});

Use the finally method to attach a handler when the promise is settled:

lazyPromise.finally(() => {
  // Perform cleanup or other operations
});

Note: The executor function will only be executed when one of the above methods is called.

License

This project is licensed under the MIT License.

FAQs

Last updated on 08 Apr 2024

Did you know?

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc