WhenAll and WhenAny

This commit is contained in:
neuecc
2020-04-21 13:36:23 +09:00
parent 082f3e7335
commit 3654a9e2f9
16 changed files with 11143 additions and 3797 deletions

View File

@@ -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);
}
}
}
}