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
Requestfrom which the gRPC request was instantiated. This reference is required by theGRPCRequestTypeprotocol.Declaration
Swift
public var vaporRequest: Request -
Handles incoming messages from the
messageStreamby 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
onNextA closure that gets a single
RequestModelvalue to handle from the stream and returnsVoidReturn Value
A succeeded future of the type
Voidthat succeeds when the stream has ended and theforEachmethod has been called for every message. -
Collects incoming messages from the
messageStreamand returns a future with an array of the collectedRequestModels.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
GRPCModeltype which is usually the response type on the event loop of thevaporRequest. This is a generic function with aResponseModelwhich implements theGRPCModelprotocol as a type constraint. It acts as shortcut to thesucceedmethod of the VaporsRequesttype.Declaration
Swift
public func succeed<ResponseModel>(value: ResponseModel) -> EventLoopFuture<ResponseModel>Parameters
valueSingle value of the
ResponseModelthat is used to succeed the created future.Return Value
A succeeded future of the type
ResponseModelon thevaporRequestevent loop.
View on GitHub
GRPCClientStreamRequest Class Reference