NeverResolvingEchoProvider.swift 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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. import EchoModel
  17. import GRPC
  18. import NIOCore
  19. /// An `Echo_EchoProvider` which returns a failed future for each RPC which resolves in the distant
  20. /// future.
  21. class NeverResolvingEchoProvider: Echo_EchoProvider {
  22. let interceptors: Echo_EchoServerInterceptorFactoryProtocol?
  23. init(interceptors: Echo_EchoServerInterceptorFactoryProtocol? = nil) {
  24. self.interceptors = interceptors
  25. }
  26. func get(
  27. request: Echo_EchoRequest,
  28. context: StatusOnlyCallContext
  29. ) -> EventLoopFuture<Echo_EchoResponse> {
  30. return context.eventLoop.scheduleTask(deadline: .distantFuture) {
  31. throw GRPCStatus.processingError
  32. }.futureResult
  33. }
  34. func expand(
  35. request: Echo_EchoRequest,
  36. context: StreamingResponseCallContext<Echo_EchoResponse>
  37. ) -> EventLoopFuture<GRPCStatus> {
  38. return context.eventLoop.scheduleTask(deadline: .distantFuture) {
  39. throw GRPCStatus.processingError
  40. }.futureResult
  41. }
  42. func collect(
  43. context: UnaryResponseCallContext<Echo_EchoResponse>
  44. ) -> EventLoopFuture<(StreamEvent<Echo_EchoRequest>) -> Void> {
  45. return context.eventLoop.scheduleTask(deadline: .distantFuture) {
  46. throw GRPCStatus.processingError
  47. }.futureResult
  48. }
  49. func update(
  50. context: StreamingResponseCallContext<Echo_EchoResponse>
  51. ) -> EventLoopFuture<(StreamEvent<Echo_EchoRequest>) -> Void> {
  52. return context.eventLoop.scheduleTask(deadline: .distantFuture) {
  53. throw GRPCStatus.processingError
  54. }.futureResult
  55. }
  56. }