Skip to content

Commit 40d928f

Browse files
committed
Bugfix: errors thrown inside async stream may not have been passed on.
1 parent 2a18c7b commit 40d928f

1 file changed

Lines changed: 14 additions & 9 deletions

File tree

Sources/WordpressReader/WordpressSite+async-internal.swift

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -65,19 +65,24 @@ extension WordpressSite {
6565
) -> AsyncThrowingStream<[T], Error> {
6666
AsyncThrowingStream { continuation in
6767
let task = Task {
68-
try await withThrowingTaskGroup(of: [T].self) { group in
69-
for url in urls {
70-
group.addTask {
71-
try Task.checkCancellation()
72-
return try await urlSession.fetchJsonData([T].self, url: url, dateDecodingStrategy: .wordpressDate)
68+
do {
69+
try await withThrowingTaskGroup(of: [T].self) { group in
70+
for url in urls {
71+
group.addTask {
72+
try Task.checkCancellation()
73+
return try await urlSession.fetchJsonData([T].self, url: url, dateDecodingStrategy: .wordpressDate)
74+
}
7375
}
74-
}
75-
76-
for try await batch in group {
77-
continuation.yield(batch)
76+
77+
for try await batch in group {
78+
continuation.yield(batch)
79+
}
80+
7881
}
7982

8083
continuation.finish()
84+
} catch {
85+
continuation.finish(throwing: error)
8186
}
8287
}
8388

0 commit comments

Comments
 (0)