From ec7064083a3aa3debfbae48aa33d3d567fc6a080 Mon Sep 17 00:00:00 2001 From: neuecc Date: Tue, 19 May 2020 03:43:06 +0900 Subject: [PATCH] Add TaskTracker to Channel --- .../Assets/Plugins/UniTask/Runtime/Channel.cs | 5 +++++ src/UniTask/Assets/Scenes/SandboxMain.cs | 17 ++++++----------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/UniTask/Assets/Plugins/UniTask/Runtime/Channel.cs b/src/UniTask/Assets/Plugins/UniTask/Runtime/Channel.cs index 7bfefbf..e391d19 100644 --- a/src/UniTask/Assets/Plugins/UniTask/Runtime/Channel.cs +++ b/src/UniTask/Assets/Plugins/UniTask/Runtime/Channel.cs @@ -193,6 +193,8 @@ namespace Cysharp.Threading.Tasks public SingleConsumerUnboundedChannelReader(SingleConsumerUnboundedChannel parent) { this.parent = parent; + + TaskTracker.TrackActiveTask(this, 4); } public override UniTask Completion @@ -304,6 +306,7 @@ namespace Cysharp.Threading.Tasks public void SingalCancellation(CancellationToken cancellationToken) { + TaskTracker.RemoveTracking(this); core.TrySetCanceled(cancellationToken); } @@ -311,10 +314,12 @@ namespace Cysharp.Threading.Tasks { if (error != null) { + TaskTracker.RemoveTracking(this); core.TrySetException(error); } else { + TaskTracker.RemoveTracking(this); core.TrySetResult(false); } } diff --git a/src/UniTask/Assets/Scenes/SandboxMain.cs b/src/UniTask/Assets/Scenes/SandboxMain.cs index dc42d22..6e7a906 100644 --- a/src/UniTask/Assets/Scenes/SandboxMain.cs +++ b/src/UniTask/Assets/Scenes/SandboxMain.cs @@ -1,20 +1,16 @@ -using System; - +using Cysharp.Threading.Tasks; using Cysharp.Threading.Tasks.Linq; using Cysharp.Threading.Tasks.Triggers; +using System; using System.Collections; using System.Collections.Generic; -using System.IO; using System.Text; using System.Threading; using System.Threading.Tasks; -using Cysharp.Threading.Tasks; using Unity.Collections; using Unity.Jobs; using UnityEngine; -using UnityEngine.Networking; using UnityEngine.UI; -using TMPro; public struct MyJob : IJob { @@ -194,7 +190,7 @@ public class SandboxMain : MonoBehaviour Debug.Log("Done"); } - async void Start() + async UniTaskVoid Start() { //var rp = new AsyncReactiveProperty(10); @@ -203,13 +199,12 @@ public class SandboxMain : MonoBehaviour //await UniTaskAsyncEnumerable.EveryUpdate().Take(10).ForEachAsync((x, i) => rp.Value = i); //rp.Dispose(); - var cts = new CancellationTokenSource(); - Running(cts.Token).Forget(); + var channel = Channel.CreateSingleConsumerUnbounded(); + Debug.Log("wait channel"); + await channel.Reader.ReadAllAsync(this.GetCancellationTokenOnDestroy()).ForEachAsync(_ => { }); - cts.CancelAfterSlim(TimeSpan.FromSeconds(3)); - } async UniTaskVoid Running(CancellationToken ct)