GRPCClientStreamRequest

public class GRPCClientStreamRequest<RequestModel> : GRPCRequestType where RequestModel : GRPCModel

A GRPCClientStream instance represents a client-streaming gRPC request that provides a forEach method which takes a closure that gets called for each incoming message of the stream, a collect method that returns all incoming messages collected as an array, and a generic succeed method to create a singe response future. It implements the GRPCRequestType that requires it to contain its Vapor Request and provides several shortcuts to several Vapor stack functionality. This is also a generic class which has type constrait for the RequestModel type which implements the GRPCModel protocol.

  • Vapor Request from which the gRPC request was instantiated. This reference is required by the GRPCRequestType protocol.

    Declaration

    Swift

    public var vaporRequest: Request
  • Handles incoming messages from the messageStream by calling the passed closure for each of these messages. It calls the closure for the next message as soon as the next message arrived.

    Declaration

    Swift

    public func forEach(onNext: @escaping ((RequestModel) -> Void)) -> EventLoopFuture<Void>

    Parameters

    onNext

    A closure that gets a single RequestModel value to handle from the stream and returns Void

    Return Value

    A succeeded future of the type Void that succeeds when the stream has ended and the forEach method has been called for every message.

  • Collects incoming messages from the messageStreamand returns a future with an array of the collected RequestModels.

    Declaration

    Swift

    public func collect() -> EventLoopFuture<[RequestModel]>

    Return Value

    A succeeded future of the type [RequestModel] that succeeds with an array of every incoming messages once the stream has ended.

  • Creates a succeeded future of a GRPCModel type which is usually the response type on the event loop of the vaporRequest. This is a generic function with a ResponseModel which implements the GRPCModel protocol as a type constraint. It acts as shortcut to the succeed method of the Vapors Requesttype.

    Declaration

    Swift

    public func succeed<ResponseModel>(value: ResponseModel) -> EventLoopFuture<ResponseModel>

    Parameters

    value

    Single value of the ResponseModel that is used to succeed the created future.

    Return Value

    A succeeded future of the type ResponseModel on the vaporRequest event loop.