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?) {
|
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
|
client.run(request) { response in
|
||||||
switch response {
|
switch response {
|
||||||
case .failure(let error):
|
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.
|
/// - Returns: A tuple of client ID and client secret.
|
||||||
|
|
|
@ -65,6 +65,8 @@ actor TimelineLikeController<Item> {
|
||||||
await loadingIndicator.end()
|
await loadingIndicator.end()
|
||||||
await emit(event: .replaceAllItems(items, token))
|
await emit(event: .replaceAllItems(items, token))
|
||||||
state = .idle
|
state = .idle
|
||||||
|
} catch is CancellationError {
|
||||||
|
return
|
||||||
} catch {
|
} catch {
|
||||||
await loadingIndicator.end()
|
await loadingIndicator.end()
|
||||||
await emit(event: .loadAllError(error, token))
|
await emit(event: .loadAllError(error, token))
|
||||||
|
@ -85,6 +87,8 @@ actor TimelineLikeController<Item> {
|
||||||
}
|
}
|
||||||
await emit(event: .prependItems(items, token))
|
await emit(event: .prependItems(items, token))
|
||||||
state = .idle
|
state = .idle
|
||||||
|
} catch is CancellationError {
|
||||||
|
return
|
||||||
} catch {
|
} catch {
|
||||||
await emit(event: .loadNewerError(error, token))
|
await emit(event: .loadNewerError(error, token))
|
||||||
state = .idle
|
state = .idle
|
||||||
|
@ -113,6 +117,8 @@ actor TimelineLikeController<Item> {
|
||||||
await loadingIndicator.end()
|
await loadingIndicator.end()
|
||||||
await emit(event: .appendItems(items, token))
|
await emit(event: .appendItems(items, token))
|
||||||
state = .idle
|
state = .idle
|
||||||
|
} catch is CancellationError {
|
||||||
|
return
|
||||||
} catch {
|
} catch {
|
||||||
await loadingIndicator.end()
|
await loadingIndicator.end()
|
||||||
await emit(event: .loadOlderError(error, token))
|
await emit(event: .loadOlderError(error, token))
|
||||||
|
|
Loading…
Reference in New Issue