jbogard / MediatR

Simple, unambitious mediator implementation in .NET
Apache License 2.0
11.14k stars 1.18k forks source link

Add support for IAsyncEnumerable<TRequest> #804

Closed iamxiaozhuang closed 1 year ago

iamxiaozhuang commented 1 year ago

I know MediatR provides a CreateStream method that returns IAsyncEnumerable with IResponse, but I am wondering if we can add support for IAsyncEnumerable with TRequest. Because I'm working on a a MediatR-based RPC (Remote Procedure Calls) example. I need to implement some functionality for Client Stream/Bidirectional Stream, such as the GRPC framework. Thank you.

jbogard commented 1 year ago

Can the request type be IAsyncEnumerable directly?

iamxiaozhuang commented 1 year ago

@jbogard
In GRPC, I can create a Bidirectional Stream method like this: public async Task BidirectionalStream(IAsyncStreamReader<BidirectionalStreamRequest> requestStream, IServerStreamWriter<BidirectionalStreamResponse> responseStream, ServerCallContext context) { while (await requestStream.MoveNext()) { //todo } } So I want to implement the same functionality in the MediatR Handler as follows: public async IAsyncEnumerable<TestStreamResponse> Handle(IAsyncEnumerable<TestStreamRequest> request, CancellationToken cancellationToken) { await foreach (var item in request) { //todo } }

jbogard commented 1 year ago

Can your response type be the full async enumerable?

github-actions[bot] commented 1 year ago

This issue is stale because it has been open 60 days with no activity. Remove stale label or comment or this will be closed in 14 days.

github-actions[bot] commented 1 year ago

This issue was closed because it has been stalled for 14 days with no activity.