1.0.0 • Published 7 years ago

collapse-decorator v1.0.0

Weekly downloads
2
License
-
Repository
github
Last release
7 years ago

Collapse Decorator Build Status Coverage Status

A decorator to collapse promises into a single pending promise to be used with async api calls.

Install

npm install collapse-decorator

Usage

import { Collapse } from 'collapse-decorator';


class Example {
    @Collapse(1000)
    callApi(param) {
        return new Promise((resolve, reject) => {
            // do something
        });
    }
}

Custom Hash-Builder

Sometimes it is necessary to use a custom hash builder function, especially if objects are passed as parameters.

import { Collapse } from 'collapse-decorator';


class Example {
    @Collapse(1000, options => `${options.secure}/${options.path}`)
    callApi(options) {
        return new Promise((resolve, reject) => {
            // do something
        });
    }
}

This will create a hash string for an object, this is not supported by the default hash function.