mirror of
https://github.com/Cysharp/UniTask.git
synced 2026-05-20 14:37:17 +00:00
WhenAll and WhenAny
This commit is contained in:
@@ -24,8 +24,6 @@ namespace UniRx.Async
|
||||
|
||||
public static UniTask DelayFrame(int delayFrameCount, PlayerLoopTiming delayTiming = PlayerLoopTiming.Update, CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
PlayerLoopHelper.Initialize(
|
||||
|
||||
if (delayFrameCount < 0)
|
||||
{
|
||||
throw new ArgumentOutOfRangeException("Delay does not allow minus delayFrameCount. delayFrameCount:" + delayFrameCount);
|
||||
@@ -121,11 +119,11 @@ namespace UniRx.Async
|
||||
{
|
||||
if (cancellationToken.IsCancellationRequested)
|
||||
{
|
||||
core.SetCanceled(cancellationToken);
|
||||
core.TrySetCanceled(cancellationToken);
|
||||
return false;
|
||||
}
|
||||
|
||||
core.SetResult(null);
|
||||
core.TrySetResult(null);
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -134,6 +132,14 @@ namespace UniRx.Async
|
||||
core.Reset();
|
||||
cancellationToken = default;
|
||||
}
|
||||
|
||||
~YieldPromise()
|
||||
{
|
||||
if (pool.TryReturn(this))
|
||||
{
|
||||
GC.ReRegisterForFinalize(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
sealed class DelayFramePromise : IUniTaskSource, IPlayerLoopItem, IPromisePoolItem
|
||||
@@ -202,13 +208,13 @@ namespace UniRx.Async
|
||||
{
|
||||
if (cancellationToken.IsCancellationRequested)
|
||||
{
|
||||
core.SetCanceled(cancellationToken);
|
||||
core.TrySetCanceled(cancellationToken);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (currentFrameCount == delayFrameCount)
|
||||
{
|
||||
core.SetResult(null);
|
||||
core.TrySetResult(null);
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -223,6 +229,14 @@ namespace UniRx.Async
|
||||
delayFrameCount = default;
|
||||
cancellationToken = default;
|
||||
}
|
||||
|
||||
~DelayFramePromise()
|
||||
{
|
||||
if (pool.TryReturn(this))
|
||||
{
|
||||
GC.ReRegisterForFinalize(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
sealed class DelayPromise : IUniTaskSource, IPlayerLoopItem, IPromisePoolItem
|
||||
@@ -292,14 +306,14 @@ namespace UniRx.Async
|
||||
{
|
||||
if (cancellationToken.IsCancellationRequested)
|
||||
{
|
||||
core.SetCanceled(cancellationToken);
|
||||
core.TrySetCanceled(cancellationToken);
|
||||
return false;
|
||||
}
|
||||
|
||||
elapsed += Time.deltaTime;
|
||||
if (elapsed >= delayFrameTimeSpan)
|
||||
{
|
||||
core.SetResult(null);
|
||||
core.TrySetResult(null);
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -313,6 +327,14 @@ namespace UniRx.Async
|
||||
elapsed = default;
|
||||
cancellationToken = default;
|
||||
}
|
||||
|
||||
~DelayPromise()
|
||||
{
|
||||
if (pool.TryReturn(this))
|
||||
{
|
||||
GC.ReRegisterForFinalize(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
sealed class DelayIgnoreTimeScalePromise : IUniTaskSource, IPlayerLoopItem, IPromisePoolItem
|
||||
@@ -382,14 +404,14 @@ namespace UniRx.Async
|
||||
{
|
||||
if (cancellationToken.IsCancellationRequested)
|
||||
{
|
||||
core.SetCanceled(cancellationToken);
|
||||
core.TrySetCanceled(cancellationToken);
|
||||
return false;
|
||||
}
|
||||
|
||||
elapsed += Time.unscaledDeltaTime;
|
||||
if (elapsed >= delayFrameTimeSpan)
|
||||
{
|
||||
core.SetResult(null);
|
||||
core.TrySetResult(null);
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -403,6 +425,14 @@ namespace UniRx.Async
|
||||
elapsed = default;
|
||||
cancellationToken = default;
|
||||
}
|
||||
|
||||
~DelayIgnoreTimeScalePromise()
|
||||
{
|
||||
if (pool.TryReturn(this))
|
||||
{
|
||||
GC.ReRegisterForFinalize(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user