/unqiue-promise

Group promises by id and execute only one at a time.

Primary LanguageTypeScript

Unique Promise

NPM Version NPM Install Size

A typical use case would be some express routes that resolve database queries that should only be called once and respond with the same result to all requests.

import uniquePromise from '@public-function/unqiue-promise';

const executeLongRunningFunction = async () => {
    // is only called once
}

const results = await Promise.all([
    uniquePromise('some-id', executeLongRunningFunction),
    uniquePromise('some-id', executeLongRunningFunction),
]);