コード例 #1
0
        public UniTask <T> WaitUntilValueChangedAsync(CancellationToken cancellationToken)
        {
            if (isDisposed)
            {
                throw new ObjectDisposedException("ReadOnlyReactiveProperty");
            }

            if (!cancellationToken.CanBeCanceled)
            {
                if (commonPromise != null)
                {
                    return(commonPromise.Task);
                }
                commonPromise = new ReactivePropertyReusablePromise <T>(CancellationToken.None);
                return(commonPromise.Task);
            }

            if (removablePromises == null)
            {
                removablePromises = new Dictionary <CancellationToken, ReactivePropertyReusablePromise <T> >(CancellationTokenEqualityComparer.Default);
            }

            if (removablePromises.TryGetValue(cancellationToken, out var newPromise))
            {
                return(newPromise.Task);
            }

            newPromise = new ReactivePropertyReusablePromise <T>(cancellationToken);
            removablePromises.Add(cancellationToken, newPromise);
            cancellationToken.RegisterWithoutCaptureExecutionContext(Callback, Tuple.Create(this, newPromise));

            return(newPromise.Task);
        }
コード例 #2
0
 public UniTask <T> WaitUntilValueChangedAsync()
 {
     if (promise != null)
     {
         return(promise.Task);
     }
     promise = new ReactivePropertyReusablePromise <T>();
     return(promise.Task);
 }