WriteBatch+Combine.swift 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. // Copyright 2021 Google LLC
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. #if canImport(Combine) && swift(>=5.0)
  15. import Combine
  16. import FirebaseFirestore
  17. @available(swift 5.0)
  18. @available(iOS 13.0, macOS 10.15, macCatalyst 13.0, tvOS 13.0, watchOS 6.0, *)
  19. public extension WriteBatch {
  20. /// Commits all of the writes in this write batch as a single atomic unit.
  21. ///
  22. /// - Returns: A publisher emitting a `Void` value once all of the writes in the batch
  23. /// have been successfully written to the backend as an atomic unit. This publisher will only
  24. /// emits when the client is online and the commit has completed against the server.
  25. /// The changes will be visible immediately.
  26. func commit() -> Future<Void, Error> {
  27. Future { promise in
  28. self.commit { error in
  29. if let error = error {
  30. promise(.failure(error))
  31. } else {
  32. promise(.success(()))
  33. }
  34. }
  35. }
  36. }
  37. }
  38. #endif