@aws-amplify/core
Version:
Core category of aws-amplify
1 lines • 1.63 kB
Source Map (JSON)
{"version":3,"file":"deDupeAsyncFunction.mjs","sources":["../../../src/utils/deDupeAsyncFunction.ts"],"sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\n/**\n * returns in-flight promise if there is one\n *\n * @param asyncFunction - asyncFunction to be deduped.\n * @returns - the return type of the callback\n */\nexport const deDupeAsyncFunction = (asyncFunction) => {\n let inflightPromise;\n return async (...args) => {\n if (inflightPromise)\n return inflightPromise;\n inflightPromise = new Promise((resolve, reject) => {\n asyncFunction(...args)\n .then(result => {\n resolve(result);\n })\n .catch(error => {\n reject(error);\n })\n .finally(() => {\n inflightPromise = undefined;\n });\n });\n return inflightPromise;\n };\n};\n"],"names":[],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACY,MAAC,mBAAmB,GAAG,CAAC,aAAa,KAAK;AACtD,IAAI,IAAI,eAAe,CAAC;AACxB,IAAI,OAAO,OAAO,GAAG,IAAI,KAAK;AAC9B,QAAQ,IAAI,eAAe;AAC3B,YAAY,OAAO,eAAe,CAAC;AACnC,QAAQ,eAAe,GAAG,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,KAAK;AAC3D,YAAY,aAAa,CAAC,GAAG,IAAI,CAAC;AAClC,iBAAiB,IAAI,CAAC,MAAM,IAAI;AAChC,gBAAgB,OAAO,CAAC,MAAM,CAAC,CAAC;AAChC,aAAa,CAAC;AACd,iBAAiB,KAAK,CAAC,KAAK,IAAI;AAChC,gBAAgB,MAAM,CAAC,KAAK,CAAC,CAAC;AAC9B,aAAa,CAAC;AACd,iBAAiB,OAAO,CAAC,MAAM;AAC/B,gBAAgB,eAAe,GAAG,SAAS,CAAC;AAC5C,aAAa,CAAC,CAAC;AACf,SAAS,CAAC,CAAC;AACX,QAAQ,OAAO,eAAe,CAAC;AAC/B,KAAK,CAAC;AACN;;;;"}