I am trying to wrap a completion function with an await/async and found a few so questions/answers and a post which helped. Even one covering wrapping a continuation which throws errors, but I want to wrap a continuation which bundles the error into the result and instead throw it. Here is my attempt:
func silentRefreshAsync(msalApplication: MSALPublicClientApplication) async throws -> RefreshedToken? {
await withCheckedContinuation { continuation in
silentRefresh(msalApplication: msalApplication) {result in
switch result {
case .failure(let error):
print("\(error)")
throw error
case.success(let token):
continuation.resume(returning: token)
}
}
}
}
But I get the error:
Invalid conversion from throwing function of type '(Result<RefreshedToken, any Error>) throws -> Void' to non-throwing function type '(Result<RefreshedToken, any Error>) -> Void'
I'm new to SwiftUI and any help would be appreciated.