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]);