Skip to content

Commit 73a2461

Browse files
committed
style: move the function closer to the non-async implementation
Asked by paulb777 [here](firebase#13407 (comment))
1 parent 4b9e3b8 commit 73a2461

File tree

2 files changed

+27
-27
lines changed

2 files changed

+27
-27
lines changed

Firestore/Swift/Source/AsyncAwait/CollectionReference+AsyncAwait.swift

-27
Original file line numberDiff line numberDiff line change
@@ -42,31 +42,4 @@ public extension CollectionReference {
4242
}
4343
}
4444
}
45-
46-
/// Encodes an instance of `Encodable` and adds a new document to this collection
47-
/// with the encoded data, assigning it a document ID automatically.
48-
///
49-
/// See `Firestore.Encoder` for more details about the encoding process.
50-
///
51-
/// - Parameters:
52-
/// - value: An instance of `Encodable` to be encoded to a document.
53-
/// - encoder: An encoder instance to use to run the encoding.
54-
/// - Throws: `Error` if the backend rejected the write.
55-
/// - Returns: A `DocumentReference` pointing to the newly created document.
56-
@discardableResult
57-
func addDocument<T: Encodable>(from value: T,
58-
encoder: Firestore.Encoder = Firestore.Encoder()) async throws
59-
-> DocumentReference {
60-
return try await withCheckedThrowingContinuation { continuation in
61-
var document: DocumentReference?
62-
document = self.addDocument(from: value, encoder: encoder) { error in
63-
if let error {
64-
continuation.resume(throwing: error)
65-
} else {
66-
// Our callbacks guarantee that we either return an error or a document.
67-
continuation.resume(returning: document!)
68-
}
69-
}
70-
}
71-
}
7245
}

Firestore/Swift/Source/Codable/CollectionReference+WriteEncodable.swift

+27
Original file line numberDiff line numberDiff line change
@@ -44,4 +44,31 @@ public extension CollectionReference {
4444
let encoded = try encoder.encode(value)
4545
return addDocument(data: encoded, completion: completion)
4646
}
47+
48+
/// Encodes an instance of `Encodable` and adds a new document to this collection
49+
/// with the encoded data, assigning it a document ID automatically.
50+
///
51+
/// See `Firestore.Encoder` for more details about the encoding process.
52+
///
53+
/// - Parameters:
54+
/// - value: An instance of `Encodable` to be encoded to a document.
55+
/// - encoder: An encoder instance to use to run the encoding.
56+
/// - Throws: `Error` if the backend rejected the write.
57+
/// - Returns: A `DocumentReference` pointing to the newly created document.
58+
@discardableResult
59+
func addDocument<T: Encodable>(from value: T,
60+
encoder: Firestore.Encoder = Firestore.Encoder()) async throws
61+
-> DocumentReference {
62+
return try await withCheckedThrowingContinuation { continuation in
63+
var document: DocumentReference?
64+
document = self.addDocument(from: value, encoder: encoder) { error in
65+
if let error {
66+
continuation.resume(throwing: error)
67+
} else {
68+
// Our callbacks guarantee that we either return an error or a document.
69+
continuation.resume(returning: document!)
70+
}
71+
}
72+
}
73+
}
4774
}

0 commit comments

Comments
 (0)