From fed4ba76b5936672a915a756499cfa22ea90071d Mon Sep 17 00:00:00 2001 From: Kazunori Tamura Date: Fri, 28 Jun 2019 10:24:31 +0900 Subject: [PATCH 1/2] Fixed nested IEnumerator does not consumed --- Assets/UniRx.Async/EnumeratorAsyncExtensions.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Assets/UniRx.Async/EnumeratorAsyncExtensions.cs b/Assets/UniRx.Async/EnumeratorAsyncExtensions.cs index 2d3114a..62b968e 100644 --- a/Assets/UniRx.Async/EnumeratorAsyncExtensions.cs +++ b/Assets/UniRx.Async/EnumeratorAsyncExtensions.cs @@ -191,7 +191,8 @@ namespace UniRx.Async } else if (current is IEnumerator e3) { - while (e3.MoveNext()) + var e4 = ConsumeEnumerator(e3); + while (e4.MoveNext()) { yield return null; } From 5a934d382fbf56743aff3d7f8a1c1874faa9705b Mon Sep 17 00:00:00 2001 From: Kazunori Tamura Date: Fri, 28 Jun 2019 11:57:06 +0900 Subject: [PATCH 2/2] Add test of nested IEnumerator --- Assets/Tests/AsyncTest.cs | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/Assets/Tests/AsyncTest.cs b/Assets/Tests/AsyncTest.cs index ac50945..d0931bc 100644 --- a/Assets/Tests/AsyncTest.cs +++ b/Assets/Tests/AsyncTest.cs @@ -376,6 +376,27 @@ namespace UniRx.AsyncTests throw new Exception("MyException"); } + [UnityTest] + public IEnumerator NestedEnumerator() => UniTask.ToCoroutine(async () => + { + var time = Time.realtimeSinceStartup; + + await ParentCoroutineEnumerator(); + + var elapsed = Time.realtimeSinceStartup - time; + ((int)Math.Round(TimeSpan.FromSeconds(elapsed).TotalSeconds, MidpointRounding.ToEven)).Should().Be(3); + }); + + IEnumerator ParentCoroutineEnumerator() + { + yield return ChildCoroutineEnumerator(); + } + + IEnumerator ChildCoroutineEnumerator() + { + yield return new WaitForSeconds(3); + } + #endif #endif }