fix Await UniTaskAsyncEnumerable.Timer is not over. #76
parent
3ef889e17d
commit
957adfad7a
|
@ -1,11 +1,9 @@
|
|||
# UniTask
|
||||
|
||||
[![CircleCI](https://circleci.com/gh/Cysharp/UniTask.svg?style=svg)](https://circleci.com/gh/Cysharp/UniTask)
|
||||
UniTask
|
||||
===
|
||||
[![GitHub Actions](https://github.com/Cysharp/UniTask/workflows/Build-Debug/badge.svg)](https://github.com/Cysharp/UniTask/actions) [![Releases](https://img.shields.io/github/release/Cysharp/UniTask.svg)](https://github.com/Cysharp/UniTask/releases)
|
||||
|
||||
Provides an efficient async/await integration to Unity.
|
||||
|
||||
> UniTask was included in UniRx before v7 but now completely separated, it no dependent each other.
|
||||
|
||||
Getting started
|
||||
---
|
||||
Install package(`UniRx.Async.unitypackage`) is available in [UniTask/releases](https://github.com/Cysharp/UniTask/releases) page.
|
||||
|
|
|
@ -86,6 +86,10 @@ namespace NetCoreSandbox
|
|||
await Task.Delay(10, cancellationToken);
|
||||
}
|
||||
|
||||
private async UniTaskVoid HogeAsync()
|
||||
{
|
||||
}
|
||||
|
||||
static async Task Main(string[] args)
|
||||
{
|
||||
await foreach (var item in UniTaskAsyncEnumerable.Range(1, 10)
|
||||
|
|
|
@ -66,6 +66,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
|||
|
||||
float elapsed;
|
||||
bool dueTimePhase;
|
||||
bool completed;
|
||||
bool disposed;
|
||||
|
||||
public _Timer(TimeSpan dueTime, TimeSpan? period, PlayerLoopTiming updateTiming, bool ignoreTimeScale, CancellationToken cancellationToken)
|
||||
|
@ -91,7 +92,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
|||
public UniTask<bool> MoveNextAsync()
|
||||
{
|
||||
// return false instead of throw
|
||||
if (disposed || cancellationToken.IsCancellationRequested) return CompletedTasks.False;
|
||||
if (disposed || cancellationToken.IsCancellationRequested || completed) return CompletedTasks.False;
|
||||
|
||||
// reset value here.
|
||||
this.elapsed = 0;
|
||||
|
@ -131,6 +132,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
|||
{
|
||||
if (period == null)
|
||||
{
|
||||
completed = true;
|
||||
completionSource.TrySetResult(false);
|
||||
return false;
|
||||
}
|
||||
|
@ -172,6 +174,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
|||
|
||||
int currentFrame;
|
||||
bool dueTimePhase;
|
||||
bool completed;
|
||||
bool disposed;
|
||||
|
||||
public _TimerFrame(int dueTimeFrameCount, int? periodFrameCount, PlayerLoopTiming updateTiming, CancellationToken cancellationToken)
|
||||
|
@ -195,7 +198,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
|||
public UniTask<bool> MoveNextAsync()
|
||||
{
|
||||
// return false instead of throw
|
||||
if (disposed || cancellationToken.IsCancellationRequested) return CompletedTasks.False;
|
||||
if (disposed || cancellationToken.IsCancellationRequested || completed) return CompletedTasks.False;
|
||||
|
||||
|
||||
// reset value here.
|
||||
|
@ -235,6 +238,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
|||
{
|
||||
if (periodFrameCount == null)
|
||||
{
|
||||
completed = true;
|
||||
completionSource.TrySetResult(false);
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -124,6 +124,20 @@ public class SandboxMain : MonoBehaviour
|
|||
|
||||
|
||||
}
|
||||
private async UniTaskVoid HogeAsync()
|
||||
{
|
||||
// await is not over
|
||||
await UniTaskAsyncEnumerable
|
||||
.TimerFrame(10)
|
||||
.ForEachAwaitAsync(async _ =>
|
||||
// .ForEachAsync(_ =>
|
||||
{
|
||||
await UniTask.Delay(1000);
|
||||
Debug.Log(Time.time);
|
||||
});
|
||||
|
||||
Debug.Log("Done");
|
||||
}
|
||||
|
||||
void Start()
|
||||
{
|
||||
|
@ -136,7 +150,7 @@ public class SandboxMain : MonoBehaviour
|
|||
|
||||
RP1 = new AsyncReactiveProperty<int>(999);
|
||||
|
||||
|
||||
HogeAsync().Forget();
|
||||
|
||||
RP1.Select(x => x * x).BindTo(text);
|
||||
|
||||
|
|
Loading…
Reference in New Issue