Merge pull request #23 from TamuraKazunori/fix_enumerator_async

Fixed nested IEnumerator does not consumed
pull/24/head
Yoshifumi Kawai 2019-06-28 20:25:02 +09:00 committed by GitHub
commit 021a1da1fa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 23 additions and 1 deletions

View File

@ -376,6 +376,27 @@ namespace UniRx.AsyncTests
throw new Exception("MyException"); 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
#endif #endif
} }

View File

@ -191,7 +191,8 @@ namespace UniRx.Async
} }
else if (current is IEnumerator e3) else if (current is IEnumerator e3)
{ {
while (e3.MoveNext()) var e4 = ConsumeEnumerator(e3);
while (e4.MoveNext())
{ {
yield return null; yield return null;
} }