Reduce nested-ness of tasks (IOS-192)

Thank you @kimar
This commit is contained in:
Nathan Mattes 2024-01-11 15:28:18 +01:00
parent c6788f5a43
commit b8ba69b930
2 changed files with 16 additions and 21 deletions

View File

@ -56,22 +56,20 @@ extension DataSourceFacade {
) async {
provider.coordinator.showLoading()
Task {
do {
guard let account = try await provider.context.apiService.fetchUser(
username: username,
domain: domain,
authenticationBox: provider.authContext.mastodonAuthenticationBox
) else {
return provider.coordinator.hideLoading()
}
provider.coordinator.hideLoading()
await coordinateToProfileScene(provider: provider, account: account)
} catch {
provider.coordinator.hideLoading()
do {
guard let account = try await provider.context.apiService.fetchUser(
username: username,
domain: domain,
authenticationBox: provider.authContext.mastodonAuthenticationBox
) else {
return provider.coordinator.hideLoading()
}
provider.coordinator.hideLoading()
await coordinateToProfileScene(provider: provider, account: account)
} catch {
provider.coordinator.hideLoading()
}
}
@ -83,7 +81,6 @@ extension DataSourceFacade {
) async {
provider.coordinator.showLoading()
Task {
do {
let account = try await provider.context.apiService.accountInfo(
domain: domain,
@ -96,7 +93,6 @@ extension DataSourceFacade {
await coordinateToProfileScene(provider: provider, account: account)
} catch {
provider.coordinator.hideLoading()
}
}
}

View File

@ -142,13 +142,12 @@ class MastodonLoginViewController: UIViewController, NeedsDependency {
authenticationViewModel
.authenticated.sink { (domain, account) in
Task {
Task { @MainActor in
do {
_ = try await self.context.authenticationService.activeMastodonUser(domain: domain, userID: account.id)
FileManager.default.store(account: account, forUserID: MastodonUserIdentifier(domain: domain, userID: account.id))
Task { @MainActor in
self.coordinator.setup()
}
self.coordinator.setup()
} catch {
assertionFailure(error.localizedDescription)
}