Type-erase the ChatGPT token refresh future (#63332)

Return a boxed `dyn Future` from `refresh_and_persist_chatgpt_token`
so callers share the code that polls the refresh future.

GitOrigin-RevId: e0a47f585348306145600561cc086676ffaceed5
This commit is contained in:
Charlie Marsh
2026-11-23 12:54:52 +00:00
committed by copyberry
parent 9819b5c869
commit 1cf4ea68b8
+13 -7
View File
@@ -3604,12 +3604,8 @@ impl AuthManager {
"Token data is not available.",
))
})?;
Box::pin(self.refresh_and_persist_chatgpt_token(
chatgpt_auth,
token_data,
reason,
))
.await
self.refresh_and_persist_chatgpt_token(chatgpt_auth, token_data, reason)
.await
}
Some(
CodexAuth::ApiKey(_)
@@ -3777,9 +3773,19 @@ impl AuthManager {
.map_err(|error| external_auth.classify_error(std::io::Error::other(error)))
}
// Erase the future's type so callers share the code that polls it.
fn refresh_and_persist_chatgpt_token<'a>(
&'a self,
auth: &'a ChatgptAuth,
tokens: TokenData,
reason: RefreshReason,
) -> Pin<Box<dyn Future<Output = Result<(), RefreshTokenError>> + Send + 'a>> {
Box::pin(self.refresh_and_persist_chatgpt_token_impl(auth, tokens, reason))
}
// Refreshes ChatGPT OAuth tokens, persists the updated auth state, and
// reloads the in-memory cache so callers immediately observe new tokens.
async fn refresh_and_persist_chatgpt_token(
async fn refresh_and_persist_chatgpt_token_impl(
&self,
auth: &ChatgptAuth,
tokens: TokenData,