Pipeline.swift 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. // Copyright 2025 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 SWIFT_PACKAGE
  15. import FirebaseFirestoreCpp
  16. @_exported import FirebaseFirestoreInternalWrapper
  17. #else
  18. @_exported import FirebaseFirestoreInternal
  19. #endif // SWIFT_PACKAGE
  20. import Foundation
  21. @available(iOS 13, tvOS 13, macOS 10.15, macCatalyst 13, watchOS 7, *)
  22. public struct Pipeline {
  23. var cppObj: firebase.firestore.api.Pipeline
  24. public init(_ cppSource: firebase.firestore.api.Pipeline) {
  25. cppObj = cppSource
  26. }
  27. @discardableResult
  28. public func GetPipelineResult() async throws -> Int {
  29. return try await withCheckedThrowingContinuation { continuation in
  30. let listener = CallbackWrapper.wrapPipelineCallback(firestore: cppObj.GetFirestore()) {
  31. result, error in
  32. if let error {
  33. continuation.resume(throwing: error)
  34. } else {
  35. // Our callbacks guarantee that we either return an error or a progress event.
  36. print("zzyzx Swift use id: \(result.pointee.id_)")
  37. PipelineResult(result.pointee)
  38. continuation.resume(returning: 5)
  39. }
  40. }
  41. cppObj.GetPipelineResult(listener)
  42. }
  43. }
  44. }