changed AsyncEnumerable.Timer reset timing

master 2.0.3-preview4
neuecc 2020-05-12 16:32:10 +09:00
parent 6a5e259006
commit 6a7a6fde5c
2 changed files with 13 additions and 8 deletions

View File

@ -93,6 +93,9 @@ namespace Cysharp.Threading.Tasks.Linq
// return false instead of throw
if (disposed || cancellationToken.IsCancellationRequested) return CompletedTasks.False;
// reset value here.
this.elapsed = 0;
completionSource.Reset();
return new UniTask<bool>(this, completionSource.Version);
}
@ -121,7 +124,6 @@ namespace Cysharp.Threading.Tasks.Linq
if (elapsed >= dueTime)
{
dueTimePhase = false;
elapsed = 0;
completionSource.TrySetResult(true);
}
}
@ -135,7 +137,6 @@ namespace Cysharp.Threading.Tasks.Linq
if (elapsed >= period)
{
elapsed = 0;
completionSource.TrySetResult(true);
}
}
@ -196,6 +197,10 @@ namespace Cysharp.Threading.Tasks.Linq
// return false instead of throw
if (disposed || cancellationToken.IsCancellationRequested) return CompletedTasks.False;
// reset value here.
this.currentFrame = 0;
completionSource.Reset();
return new UniTask<bool>(this, completionSource.Version);
}
@ -220,11 +225,10 @@ namespace Cysharp.Threading.Tasks.Linq
if (dueTimePhase)
{
if (currentFrame++ == dueTimeFrameCount)
if (currentFrame++ >= dueTimeFrameCount)
{
dueTimePhase = false;
completionSource.TrySetResult(true);
currentFrame = 0;
}
}
else
@ -235,10 +239,9 @@ namespace Cysharp.Threading.Tasks.Linq
return false;
}
if (++currentFrame == periodFrameCount)
if (++currentFrame >= periodFrameCount)
{
completionSource.TrySetResult(true);
currentFrame = 0;
}
}

View File

@ -145,11 +145,13 @@ public class SandboxMain : MonoBehaviour
//StartCoroutine(cor);
// UniTaskAsyncEnumerable.EveryUpdate(PlayerLoopTiming.FixedUpdate)
// await UniTask.Yield(PlayerLoopTiming.EarlyUpdate);
await UniTask.Yield(PlayerLoopTiming.Update);
Debug.Log("Start:" + Time.frameCount);
await UniTaskAsyncEnumerable.TimerFrame(3, 5, PlayerLoopTiming.LastPostLateUpdate).ForEachAsync(_ =>
await UniTaskAsyncEnumerable.TimerFrame(3, 5, PlayerLoopTiming.Update).ForEachAsync(_ =>
{
Debug.Log("Call:" + Time.frameCount);
}, cancellationToken: this.GetCancellationTokenOnDestroy());