0

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.

lcj
  • 1,355
  • 16
  • 37

1 Answers1

1

Try changing withCheckedContinuation with withCheckedThrowingContinuation, as your function declaration indicates that the function can throw.

user3565259
  • 101
  • 9