Skip to main content

Setup

Offers easy installation and modularized configuration.

Install

Install the library from npm by running the following command

npm i wrapper-async

This will install the module in your project.

NPM support only

This module is currently available only on NPM and not on YARN.

Configuration

You can use the following code to configure your asyncWrapper global object:

config/wrappers.js
import WrapperAsyncBuilder from "wrapper-async";

const DEBOUNCE_DELAY = 1000;
const RETRY_LIMIT = 3;
const subscriber = {
onEvent: (val) => {
// handle event here
},
};

export const asyncWrapper = new WrapperAsyncBuilder()
.attachMetaData({ msg: "Receiving in subscriber" })
.subscribers([subscriber])
.debouce(DEBOUNCE_DELAY)
.retry(RETRY_LIMIT)
.enableCache(true)
.build();

You have the following entities to configure before using the asyncWrapper as per your needs:

PrototypePurposeDefault value
.debounce(delay_in_ms: number)This function defines the debounce delay for the execution of user's async function500
.subscribers(event_listeners: Subscriber[])This function takes in a list of event listening functions that are triggered with the event_type and value[]
.attachMetaData(obj: any)This function takes in an object of any type. This adds as the metadeta for the event listening functions undefined
.retry(retry_limit: number)This configures the retry limit before throwing an error whenever the user's async function fails or rejects3
.enableCache(should_enable_cache: boolean)This enforces the module to enable cache. This will treat your async function as a pure function, returning same result for same parametersfalse
.build()Creates an AsyncWrapper function with a single .execute function in it