UNPKG

@azure/msal-browser

Version:
65 lines (63 loc) • 2.02 kB
/*! @azure/msal-browser v5.25.0 2026-10-06 */ 'use strict'; /* * Copyright (c) Microsoft Corporation. All rights reserved. * Licensed under the MIT License. */ /** * Correlates outbound requests with inbound responses by `requestId`. */ class PendingRequestRegistry { constructor() { this.pending = new Map(); } /** * Register a pending request. Returns a promise that resolves when a * response with the matching `requestId` arrives, or rejects if the * caller invokes `reject` for that id. */ register(requestId) { return new Promise((resolve, reject) => { this.pending.set(requestId, { resolve, reject }); }); } /** Resolve a pending request. No-op if `requestId` isn't registered. */ resolve(requestId, response) { const entry = this.pending.get(requestId); if (entry === undefined) { return; } this.pending.delete(requestId); entry.resolve(response); } /** Reject a pending request. No-op if `requestId` isn't registered. */ reject(requestId, reason) { const entry = this.pending.get(requestId); if (entry === undefined) { return; } this.pending.delete(requestId); entry.reject(reason); } /** True if `requestId` has an in-flight registration. */ has(requestId) { return this.pending.has(requestId); } /** * Register, then invoke `send` synchronously. If `send` throws, the * pending entry is cleared and the promise rejects with the thrown * error. */ async sendAndAwait(message, send) { const promise = this.register(message.requestId); try { send(message); } catch (err) { this.reject(message.requestId, err); } return promise; } } export { PendingRequestRegistry }; //# sourceMappingURL=PendingRequestRegistry.mjs.map