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 Nov 6, 2024
1 parent 4e13fe5 commit 77e8c60
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 77e8c60

Please sign in to comment.