diff --git a/src/UniTask/Assets/Plugins/UniTask/Runtime/AsyncReactiveProperty.cs b/src/UniTask/Assets/Plugins/UniTask/Runtime/AsyncReactiveProperty.cs index 4e51e43..e196222 100644 --- a/src/UniTask/Assets/Plugins/UniTask/Runtime/AsyncReactiveProperty.cs +++ b/src/UniTask/Assets/Plugins/UniTask/Runtime/AsyncReactiveProperty.cs @@ -4,13 +4,13 @@ using System.Threading; namespace Cysharp.Threading.Tasks { - public interface IAsyncReadOnlyReactiveProperty : IUniTaskAsyncEnumerable + public interface IReadOnlyAsyncReactiveProperty : IUniTaskAsyncEnumerable { T Value { get; } IUniTaskAsyncEnumerable WithoutCurrent(); } - public interface IAsyncReactiveProperty : IAsyncReadOnlyReactiveProperty + public interface IAsyncReactiveProperty : IReadOnlyAsyncReactiveProperty { new T Value { get; set; } } @@ -56,7 +56,7 @@ namespace Cysharp.Threading.Tasks public void Dispose() { - triggerEvent.SetCanceled(CancellationToken.None); + triggerEvent.SetCompleted(); } class WithoutCurrentEnumerable : IUniTaskAsyncEnumerable @@ -74,7 +74,7 @@ namespace Cysharp.Threading.Tasks } } - sealed class Enumerator : MoveNextSource, IUniTaskAsyncEnumerator, IResolveCancelPromise + sealed class Enumerator : MoveNextSource, IUniTaskAsyncEnumerator, ITriggerHandler { static Action cancellationCallback = CancellationCallback; @@ -128,17 +128,20 @@ namespace Cysharp.Threading.Tasks return default; } - public bool TrySetResult(T value) + public void OnNext(T value) { this.value = value; completionSource.TrySetResult(true); - return true; } - public bool TrySetCanceled(CancellationToken cancellationToken = default) + public void OnCanceled(CancellationToken cancellationToken) { DisposeAsync().Forget(); - return true; + } + + public void OnCompleted() + { + completionSource.TrySetResult(false); } static void CancellationCallback(object state) diff --git a/src/UniTask/Assets/Scenes/SandboxMain.cs b/src/UniTask/Assets/Scenes/SandboxMain.cs index 40a8583..6ba3ae5 100644 --- a/src/UniTask/Assets/Scenes/SandboxMain.cs +++ b/src/UniTask/Assets/Scenes/SandboxMain.cs @@ -194,23 +194,28 @@ public class SandboxMain : MonoBehaviour Debug.Log("Done"); } - void Start() + async void Start() { - var channel = Channel.CreateSingleConsumerUnbounded(); + //var rp = new AsyncReactiveProperty(10); - var reader = channel.Reader; + //Running(rp).Forget(); - WaitForChannelAsync(reader, this.GetCancellationTokenOnDestroy()).Forget(); + //await UniTaskAsyncEnumerable.EveryUpdate().Take(10).ForEachAsync((x, i) => rp.Value = i); - var writer = channel.Writer; + //rp.Dispose(); - writer.TryWrite(1); - writer.TryWrite(2); - writer.TryWrite(3); - writer.Complete(new Exception()); + await this.GetAsyncUpdateTrigger().ForEachAsync(x => Debug.Log("yeah")); + Debug.Log("DONE"); } + async UniTaskVoid Running(IReadOnlyAsyncReactiveProperty rp) + { + Debug.Log("BEGIN"); + await rp.ForEachAsync(x => Debug.Log("AR:" + x)); + Debug.Log("DONE"); + } + async UniTaskVoid WaitForChannelAsync(ChannelReader reader, CancellationToken token) { try