Skip to content

Commit 1d86d21

Browse files
committed
clean up in-flight logic
1 parent 6e61787 commit 1d86d21

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

packages/app-check/src/internal-api.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,10 @@ export async function getToken(
9191
};
9292
}
9393

94-
let waitedForInFlightRequest = false;
94+
// Only set to true if this `getToken()` call is making the actual
95+
// REST call to the exchange endpoint, versus waiting for an already
96+
// in-flight call (see debug and regular exchange endpoint paths below)
97+
let shouldCallListeners = false;
9598

9699
/**
97100
* DEBUG MODE
@@ -108,8 +111,7 @@ export async function getToken(
108111
state.exchangeTokenPromise = undefined;
109112
return token;
110113
});
111-
} else {
112-
waitedForInFlightRequest = true;
114+
shouldCallListeners = true;
113115
}
114116
const tokenFromDebugExchange: AppCheckTokenInternal =
115117
await state.exchangeTokenPromise;
@@ -133,8 +135,7 @@ export async function getToken(
133135
state.exchangeTokenPromise = undefined;
134136
return token;
135137
});
136-
} else {
137-
waitedForInFlightRequest = true;
138+
shouldCallListeners = true;
138139
}
139140
token = await state.exchangeTokenPromise;
140141
} catch (e) {
@@ -164,7 +165,7 @@ export async function getToken(
164165
await writeTokenToStorage(app, token);
165166
}
166167

167-
if (!waitedForInFlightRequest) {
168+
if (!shouldCallListeners) {
168169
notifyTokenListeners(app, interopTokenResult);
169170
}
170171
return interopTokenResult;

0 commit comments

Comments
 (0)