Skip to content

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

License

Notifications You must be signed in to change notification settings

ai-zen/lazy-promise

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.

About

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

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published