mirror of
https://github.com/Cysharp/UniTask.git
synced 2026-05-27 02:40:08 +00:00
Add overload in UniTask.WaitUntil, UniTask.WaitWhile and UniTask.Defer to avoid closure allocation
This commit is contained in:
@@ -145,6 +145,11 @@ namespace Cysharp.Threading.TasksTests
|
||||
public int MyProperty { get; set; }
|
||||
}
|
||||
|
||||
class MyBoolenClass
|
||||
{
|
||||
public bool MyProperty { get; set; }
|
||||
}
|
||||
|
||||
[UnityTest]
|
||||
public IEnumerator WaitUntil() => UniTask.ToCoroutine(async () =>
|
||||
{
|
||||
@@ -159,6 +164,20 @@ namespace Cysharp.Threading.TasksTests
|
||||
diff.Should().Be(11);
|
||||
});
|
||||
|
||||
[UnityTest]
|
||||
public IEnumerator WaitUntilWithState() => UniTask.ToCoroutine(async () =>
|
||||
{
|
||||
var v = new MyBoolenClass { MyProperty = false };
|
||||
|
||||
UniTask.DelayFrame(10, PlayerLoopTiming.PostLateUpdate).ContinueWith(() => v.MyProperty = true).Forget();
|
||||
|
||||
var startFrame = Time.frameCount;
|
||||
await UniTask.WaitUntil(v, static v => v.MyProperty, PlayerLoopTiming.EarlyUpdate);
|
||||
|
||||
var diff = Time.frameCount - startFrame;
|
||||
diff.Should().Be(11);
|
||||
});
|
||||
|
||||
[UnityTest]
|
||||
public IEnumerator WaitWhile() => UniTask.ToCoroutine(async () =>
|
||||
{
|
||||
@@ -173,6 +192,20 @@ namespace Cysharp.Threading.TasksTests
|
||||
diff.Should().Be(11);
|
||||
});
|
||||
|
||||
[UnityTest]
|
||||
public IEnumerator WaitWhileWithState() => UniTask.ToCoroutine(async () =>
|
||||
{
|
||||
var v = new MyBoolenClass { MyProperty = true };
|
||||
|
||||
UniTask.DelayFrame(10, PlayerLoopTiming.PostLateUpdate).ContinueWith(() => v.MyProperty = false).Forget();
|
||||
|
||||
var startFrame = Time.frameCount;
|
||||
await UniTask.WaitWhile(v, static v => v.MyProperty, PlayerLoopTiming.EarlyUpdate);
|
||||
|
||||
var diff = Time.frameCount - startFrame;
|
||||
diff.Should().Be(11);
|
||||
});
|
||||
|
||||
[UnityTest]
|
||||
public IEnumerator WaitUntilValueChanged() => UniTask.ToCoroutine(async () =>
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user