IAsyncEnumerable is not continally streams Duplex code-first gRPC
Hi,
I've finally confirmed, what is my issue.
[ServiceContract]
public interface ISharedContract<DTO>
where DTO : class
{
[OperationContract]
IAsyncEnumerable<GetListResponse<DTO>> GetPageAsync(IAsyncEnumerable<GetListRequest> requests, CancellationToken cancellationToken);
I have working Duplex with code-first gRPC. No issue here - everything working. Except on big difference from PROTOBUF-first approach. Streaming to server is awaiting for entire IAsyncEnumerable to compute rather to stream real Duplex. Seems to be, that IAsyncEnumerable is only way how to write Duplex in code-first approach. However:
private CancellationTokenSource channelEnd = new CancellationTokenSource();
private ConcurrentQueue<GetListRequest> requests = new ConcurrentQueue<GetListRequest>();
IAsyncEnumerable<GetListResponse<TContractItem>>? duplexPaging = null;
async IAsyncEnumerable<GetListRequest> GetRequests(GetListRequest message)
{
while (!channelEnd.IsCancellationRequested)
{
yield return message;
await Task.Delay(20000, channelEnd.Token); // Wait before checking for new messages
}
}
Is awaiting whole cycle rather than to stream once yield return hit. I've confirmed right now, that if I compute like 5 to 10 requests beforehand, then whole bulk is being streamed to server and only then server's lazy foreach is being hit. However I absolutely need continuous Duplex where both server and client can stream once one single message is computed. So, is there any workaround, or PROTOBUF with stream writting is the only option?
Kind regards.