forked from shadowfacts/Tusker
Handle task cancellation in MastodonController.run
This commit is contained in:
parent
b47876dc3d
commit
7bdbd9f71a
|
@ -68,7 +68,7 @@ class MastodonController: ObservableObject {
|
|||
}
|
||||
|
||||
func run<Result>(_ request: Request<Result>) async throws -> (Result, Pagination?) {
|
||||
return try await withCheckedThrowingContinuation({ continuation in
|
||||
let result: (Result, Pagination?) = try await withCheckedThrowingContinuation({ continuation in
|
||||
client.run(request) { response in
|
||||
switch response {
|
||||
case .failure(let error):
|
||||
|
@ -78,6 +78,8 @@ class MastodonController: ObservableObject {
|
|||
}
|
||||
}
|
||||
})
|
||||
try Task.checkCancellation()
|
||||
return result
|
||||
}
|
||||
|
||||
/// - Returns: A tuple of client ID and client secret.
|
||||
|
|
|
@ -65,6 +65,8 @@ actor TimelineLikeController<Item> {
|
|||
await loadingIndicator.end()
|
||||
await emit(event: .replaceAllItems(items, token))
|
||||
state = .idle
|
||||
} catch is CancellationError {
|
||||
return
|
||||
} catch {
|
||||
await loadingIndicator.end()
|
||||
await emit(event: .loadAllError(error, token))
|
||||
|
@ -85,6 +87,8 @@ actor TimelineLikeController<Item> {
|
|||
}
|
||||
await emit(event: .prependItems(items, token))
|
||||
state = .idle
|
||||
} catch is CancellationError {
|
||||
return
|
||||
} catch {
|
||||
await emit(event: .loadNewerError(error, token))
|
||||
state = .idle
|
||||
|
@ -113,6 +117,8 @@ actor TimelineLikeController<Item> {
|
|||
await loadingIndicator.end()
|
||||
await emit(event: .appendItems(items, token))
|
||||
state = .idle
|
||||
} catch is CancellationError {
|
||||
return
|
||||
} catch {
|
||||
await loadingIndicator.end()
|
||||
await emit(event: .loadOlderError(error, token))
|
||||
|
|
Loading…
Reference in New Issue