From 7d958bfaf8a7bf6802b836fb412f81aabebf4ab3 Mon Sep 17 00:00:00 2001 From: Ahmed Zamil Date: Mon, 2 Feb 2026 22:22:47 +0300 Subject: [PATCH] IAsyncEnumerable --- Esiur/Esiur.csproj | 1 + .../Net/IIP/DistributedConnectionProtocol.cs | 31 ++++++++++++++++++- Esiur/Resource/Template/FunctionTemplate.cs | 2 +- 3 files changed, 32 insertions(+), 2 deletions(-) diff --git a/Esiur/Esiur.csproj b/Esiur/Esiur.csproj index 9507c3b..7a75482 100644 --- a/Esiur/Esiur.csproj +++ b/Esiur/Esiur.csproj @@ -39,6 +39,7 @@ + diff --git a/Esiur/Net/IIP/DistributedConnectionProtocol.cs b/Esiur/Net/IIP/DistributedConnectionProtocol.cs index 451b910..dd6d772 100644 --- a/Esiur/Net/IIP/DistributedConnectionProtocol.cs +++ b/Esiur/Net/IIP/DistributedConnectionProtocol.cs @@ -1362,7 +1362,36 @@ partial class DistributedConnection return; } - if (rt is System.Collections.IEnumerable && !(rt is Array || rt is Map || rt is string)) + if (rt is IAsyncEnumerable) + { + var enu = rt as IAsyncEnumerable; + var enumerator = enu.GetAsyncEnumerator(); + Task.Run(async () => + { + try + { + while (await enumerator.MoveNextAsync()) + { + var v = enumerator.Current; + SendChunk(callback, v); + } + + SendReply(IIPPacketReply.Completed, callback); + + if (context != null) + context.Ended = true; + } + catch (Exception ex) + { + if (context != null) + context.Ended = true; + + var (code, msg) = SummerizeException(ex); + SendError(ErrorType.Exception, callback, code, msg); + } + }); + } + else if (rt is System.Collections.IEnumerable && !(rt is Array || rt is Map || rt is string)) { var enu = rt as System.Collections.IEnumerable; diff --git a/Esiur/Resource/Template/FunctionTemplate.cs b/Esiur/Resource/Template/FunctionTemplate.cs index 550d4e2..913d795 100644 --- a/Esiur/Resource/Template/FunctionTemplate.cs +++ b/Esiur/Resource/Template/FunctionTemplate.cs @@ -143,7 +143,7 @@ public class FunctionTemplate : MemberTemplate { rtType = TRU.FromType(mi.ReturnType.GetGenericArguments()[0]); } - else if (genericRtType == typeof(IEnumerable<>))// || genericRtType == typeof(IAsyncEnumerable<>)) + else if (genericRtType == typeof(IEnumerable<>) || genericRtType == typeof(IAsyncEnumerable<>)) { // get export rtType = TRU.FromType(mi.ReturnType.GetGenericArguments()[0]);