Skip to content

Instantly share code, notes, and snippets.

@jacobsapps
Created August 15, 2025 13:51
Show Gist options
  • Save jacobsapps/a09db7559781edaa62f220146774b0e8 to your computer and use it in GitHub Desktop.
Save jacobsapps/a09db7559781edaa62f220146774b0e8 to your computer and use it in GitHub Desktop.
actor AuthServiceImpl: AuthService {
var tokenTask: Task<String, Error>?
func getBearerToken() async throws -> String {
if tokenTask == nil {
tokenTask = Task { try await fetchValidAuthToken() }
}
defer { tokenTask = nil }
return try await tokenTask!.value
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment