@aws-amplify/auth
Version:
Auth category of aws-amplify
1 lines • 3.72 kB
Source Map (JSON)
{"version":3,"file":"inflightPromise.mjs","sources":["../../../../../../src/providers/cognito/utils/oauth/inflightPromise.ts"],"sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nconst inflightPromises = [];\n// Module-level singleton backstop timer for the inflight OAuth blocking\n// deadline. A single timer (not one per waiter) is sufficient because all\n// parked waiters share one release (`resolveAndClearInflightPromises` drains\n// them all), and every park re-arms it with the current deadline.\nlet deadlineTimer;\nexport const addInflightPromise = (resolver) => {\n inflightPromises.push(resolver);\n};\n/**\n * Arms (or re-arms) the backstop timer that releases parked token consumers\n * once the inflight OAuth blocking deadline passes.\n *\n * On fire it re-reads the deadline instead of trusting the armed one: a fresh\n * `signInWithRedirect` may have renewed it (re-arm for the new deadline), or\n * the flow may have been released through another path already (the re-check\n * returns `undefined` and draining is a no-op). The release is purely local —\n * it never mutates shared OAuth state, so another tab's still-running flow is\n * left intact.\n *\n * Note: browsers throttle timers in background tabs, which may delay (never\n * prevent) this release; the cross-tab storage listener remains the fast path.\n */\nexport const armInflightDeadline = (deadline, recheckDeadline) => {\n if (deadlineTimer !== undefined) {\n clearTimeout(deadlineTimer);\n }\n deadlineTimer = setTimeout(() => {\n deadlineTimer = undefined;\n recheckDeadline()\n .then(renewedDeadline => {\n if (renewedDeadline !== undefined) {\n armInflightDeadline(renewedDeadline, recheckDeadline);\n return;\n }\n resolveAndClearInflightPromises();\n })\n // Fail open: an error while re-checking (e.g. auth config torn down)\n // must release the waiters rather than leave them parked forever.\n .catch(() => {\n resolveAndClearInflightPromises();\n });\n }, Math.max(0, deadline - Date.now()));\n};\nexport const resolveAndClearInflightPromises = () => {\n // The waiters this timer guarded are being released through this very call\n // (whatever triggered it) — clear it so no stale timer outlives its waiters.\n if (deadlineTimer !== undefined) {\n clearTimeout(deadlineTimer);\n deadlineTimer = undefined;\n }\n while (inflightPromises.length)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