UNPKG

@aws-amplify/core

Version:
35 lines (33 loc) 1.06 kB
'use strict'; // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 Object.defineProperty(exports, "__esModule", { value: true }); exports.deDupeAsyncFunction = void 0; /** * returns in-flight promise if there is one * * @param asyncFunction - asyncFunction to be deduped. * @returns - the return type of the callback */ const deDupeAsyncFunction = (asyncFunction) => { let inflightPromise; return async (...args) => { if (inflightPromise) return inflightPromise; inflightPromise = new Promise((resolve, reject) => { asyncFunction(...args) .then(result => { resolve(result); }) .catch(error => { reject(error); }) .finally(() => { inflightPromise = undefined; }); }); return inflightPromise; }; }; exports.deDupeAsyncFunction = deDupeAsyncFunction; //# sourceMappingURL=deDupeAsyncFunction.js.map