diff --git a/README.md b/README.md index 9ee782a..e804ca5 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/src/UniTask.NetCoreSandbox/Program.cs b/src/UniTask.NetCoreSandbox/Program.cs index 6ca55dc..e383db7 100644 --- a/src/UniTask.NetCoreSandbox/Program.cs +++ b/src/UniTask.NetCoreSandbox/Program.cs @@ -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) diff --git a/src/UniTask/Assets/Plugins/UniTask/Runtime/Linq/UnityExtensions/Timer.cs b/src/UniTask/Assets/Plugins/UniTask/Runtime/Linq/UnityExtensions/Timer.cs index d8d370d..473949b 100644 --- a/src/UniTask/Assets/Plugins/UniTask/Runtime/Linq/UnityExtensions/Timer.cs +++ b/src/UniTask/Assets/Plugins/UniTask/Runtime/Linq/UnityExtensions/Timer.cs @@ -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 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 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; } diff --git a/src/UniTask/Assets/Scenes/SandboxMain.cs b/src/UniTask/Assets/Scenes/SandboxMain.cs index f9e208a..2d94ef3 100644 --- a/src/UniTask/Assets/Scenes/SandboxMain.cs +++ b/src/UniTask/Assets/Scenes/SandboxMain.cs @@ -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(999); - + HogeAsync().Forget(); RP1.Select(x => x * x).BindTo(text);