HomeiOS Developmentios - Swift concurrency. How you can rethrow in catch block? Additionally...

ios – Swift concurrency. How you can rethrow in catch block? Additionally about recursion in async/await


To begin with I’ve a operate for get model from API.

func getVersionAsync() async throws -> VersionEntity {
    return attempt await withCheckedThrowingContinuation { continuation in
        versionTask.getVersion { lead to
            change consequence {
            case .success(let response):
                continuation.resume(returning: response.merchandise)
            case .failure(let error):
                continuation.resume(throwing: error)
            }
        }
    }
}

Then I have to deal with it or repeat request after 5 seconds:

func checkVersion() async {
    do {
        let versionEntity = attempt await getVersionAsync()
        // deal with versionEntity
    } catch {
        attempt await Process.sleep(nanoseconds: 5) <- Errors thrown from right here are usually not dealt with
        await checkVersion()
    }
}

There may be an error Errors thrown from right here are usually not dealt with. What’s the appropriate method to do that in swift concurrency?

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments