vyshane/grpc-swift-combine

Recieve value of each request in stream

Closed this issue · 1 comments

Is there a way to get the completion event of each request in the request array in the case of a client stream request?
I get only one value when all queries in the array are completed

  func create() -> AnyPublisher<UInt64, Error> {
      let requests = requests
      let requestStream: AnyPublisher<Node_UploadPartsReq, Error> = Publishers.Sequence(sequence: requests)
          .eraseToAnyPublisher()
      let grpc = GRPCExecutor()
      return grpc.call(client.uploadParts)(requestStream)
          .map({ _ in
              return UploadPartsResponse(nodeId: connection.nodeId) })
          .replaceEmpty(with: UploadPartsResponse(nodeId: connection.nodeId))
          .mapError({ error in
              Log.error("\(error)")
              return AppError.convertFrom(error)
          })
          .map({ response in
              return response.nodeId
          })
          .eraseToAnyPublisher()
  }

No, semantically publishers only send one completion event, at the end. If you require confirmation for each item, consider switching to a unary RPC. For example:

rpc CreateUploadSession (CreateUploadSessionRequest) returns (UploadSession);

rpc UploadPart (UploadPartRequest) returns (UploadPartResponse);

rpc CompleteUploadSession (CompleteUploadSessionRequest) returns (UploadSession);

Whereby:

message UploadSession {
  string id = 1;
  bool completed = 2;
}

message UploadPartRequest {
  string session_id = 1;
  bytes part = 2;
}

message CompleteUploadSession {
  string id = 1;
}

You first create an upload session, then upload parts via repeated calls to the UploadPart RPC. You can then complete the session when you are done.