Skip to content

Commit

Permalink
feat: catch the throwing error and resume it to the continuation
Browse files Browse the repository at this point in the history
  • Loading branch information
MojtabaHs committed Jul 27, 2024
1 parent 6005fe9 commit af4e2b8
Showing 1 changed file with 10 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,17 @@ public extension CollectionReference {
-> DocumentReference {
return try await withCheckedThrowingContinuation { continuation in
var document: DocumentReference?
document = self.addDocument(from: value, encoder: encoder) { error in
if let error {
continuation.resume(throwing: error)
} else {
// Our callbacks guarantee that we either return an error or a document.
continuation.resume(returning: document!)
do {
document = try self.addDocument(from: value, encoder: encoder) { error in
if let error {
continuation.resume(throwing: error)
} else {
// Our callbacks guarantee that we either return an error or a document.
continuation.resume(returning: document!)
}
}
} catch {
continuation.resume(throwing: error)
}
}
}
Expand Down

0 comments on commit af4e2b8

Please sign in to comment.