GRPCClient+AsyncAwaitSupport.swift 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. /*
  2. * Copyright 2021, gRPC Authors All rights reserved.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #if compiler(>=5.5)
  17. import SwiftProtobuf
  18. @available(macOS 12, iOS 15, tvOS 15, watchOS 8, *)
  19. extension GRPCClient {
  20. public func makeAsyncUnaryCall<Request: Message, Response: Message>(
  21. path: String,
  22. request: Request,
  23. callOptions: CallOptions? = nil,
  24. interceptors: [ClientInterceptor<Request, Response>] = [],
  25. responseType: Response.Type = Response.self
  26. ) -> GRPCAsyncUnaryCall<Request, Response> {
  27. return self.channel.makeAsyncUnaryCall(
  28. path: path,
  29. request: request,
  30. callOptions: callOptions ?? self.defaultCallOptions,
  31. interceptors: interceptors
  32. )
  33. }
  34. public func makeAsyncUnaryCall<Request: GRPCPayload, Response: GRPCPayload>(
  35. path: String,
  36. request: Request,
  37. callOptions: CallOptions? = nil,
  38. interceptors: [ClientInterceptor<Request, Response>] = [],
  39. responseType: Response.Type = Response.self
  40. ) -> GRPCAsyncUnaryCall<Request, Response> {
  41. return self.channel.makeAsyncUnaryCall(
  42. path: path,
  43. request: request,
  44. callOptions: callOptions ?? self.defaultCallOptions,
  45. interceptors: interceptors
  46. )
  47. }
  48. public func makeAsyncServerStreamingCall<
  49. Request: SwiftProtobuf.Message,
  50. Response: SwiftProtobuf.Message
  51. >(
  52. path: String,
  53. request: Request,
  54. callOptions: CallOptions? = nil,
  55. interceptors: [ClientInterceptor<Request, Response>] = [],
  56. responseType: Response.Type = Response.self
  57. ) -> GRPCAsyncServerStreamingCall<Request, Response> {
  58. return self.channel.makeAsyncServerStreamingCall(
  59. path: path,
  60. request: request,
  61. callOptions: callOptions ?? self.defaultCallOptions,
  62. interceptors: interceptors
  63. )
  64. }
  65. public func makeAsyncServerStreamingCall<Request: GRPCPayload, Response: GRPCPayload>(
  66. path: String,
  67. request: Request,
  68. callOptions: CallOptions? = nil,
  69. interceptors: [ClientInterceptor<Request, Response>] = [],
  70. responseType: Response.Type = Response.self
  71. ) -> GRPCAsyncServerStreamingCall<Request, Response> {
  72. return self.channel.makeAsyncServerStreamingCall(
  73. path: path,
  74. request: request,
  75. callOptions: callOptions ?? self.defaultCallOptions,
  76. interceptors: interceptors
  77. )
  78. }
  79. public func makeAsyncClientStreamingCall<
  80. Request: SwiftProtobuf.Message,
  81. Response: SwiftProtobuf.Message
  82. >(
  83. path: String,
  84. callOptions: CallOptions? = nil,
  85. interceptors: [ClientInterceptor<Request, Response>] = [],
  86. requestType: Request.Type = Request.self,
  87. responseType: Response.Type = Response.self
  88. ) -> GRPCAsyncClientStreamingCall<Request, Response> {
  89. return self.channel.makeAsyncClientStreamingCall(
  90. path: path,
  91. callOptions: callOptions ?? self.defaultCallOptions,
  92. interceptors: interceptors
  93. )
  94. }
  95. public func makeAsyncClientStreamingCall<Request: GRPCPayload, Response: GRPCPayload>(
  96. path: String,
  97. callOptions: CallOptions? = nil,
  98. interceptors: [ClientInterceptor<Request, Response>] = [],
  99. requestType: Request.Type = Request.self,
  100. responseType: Response.Type = Response.self
  101. ) -> GRPCAsyncClientStreamingCall<Request, Response> {
  102. return self.channel.makeAsyncClientStreamingCall(
  103. path: path,
  104. callOptions: callOptions ?? self.defaultCallOptions,
  105. interceptors: interceptors
  106. )
  107. }
  108. public func makeAsyncBidirectionalStreamingCall<
  109. Request: SwiftProtobuf.Message,
  110. Response: SwiftProtobuf.Message
  111. >(
  112. path: String,
  113. callOptions: CallOptions? = nil,
  114. interceptors: [ClientInterceptor<Request, Response>] = [],
  115. requestType: Request.Type = Request.self,
  116. responseType: Response.Type = Response.self
  117. ) -> GRPCAsyncBidirectionalStreamingCall<Request, Response> {
  118. return self.channel.makeAsyncBidirectionalStreamingCall(
  119. path: path,
  120. callOptions: callOptions ?? self.defaultCallOptions,
  121. interceptors: interceptors
  122. )
  123. }
  124. public func makeAsyncBidirectionalStreamingCall<
  125. Request: GRPCPayload,
  126. Response: GRPCPayload
  127. >(
  128. path: String,
  129. callOptions: CallOptions? = nil,
  130. interceptors: [ClientInterceptor<Request, Response>] = [],
  131. requestType: Request.Type = Request.self,
  132. responseType: Response.Type = Response.self
  133. ) -> GRPCAsyncBidirectionalStreamingCall<Request, Response> {
  134. return self.channel.makeAsyncBidirectionalStreamingCall(
  135. path: path,
  136. callOptions: callOptions ?? self.defaultCallOptions,
  137. interceptors: interceptors
  138. )
  139. }
  140. }
  141. #endif