public static Task <T> WaitUntilExecuteAsync <T>(this IAsyncReactiveCommand <T> source, CancellationToken cancellationToken = default(CancellationToken))
        {
            var tcs = new CancellableTaskCompletionSource <T>();

            var subscription = source.Subscribe(x => { tcs.TrySetResult(x); return(Observable.ReturnUnit()); });

            cancellationToken.Register(Callback, Tuple.Create(tcs, subscription), false);

            return(tcs.Task);
        }
        public static Task <T> WaitUntilValueChangedAsync <T>(this IReadOnlyReactiveProperty <T> source, CancellationToken cancellationToken = default(CancellationToken))
        {
            var tcs = new CancellableTaskCompletionSource <T>();

            var subscription = source.Subscribe(x => tcs.TrySetResult(x), ex => tcs.TrySetException(ex), () => tcs.TrySetCanceled());

            cancellationToken.Register(Callback, Tuple.Create(tcs, subscription), false);

            return(tcs.Task);
        }
        public static Task <T> WaitUntilExecuteAsync <T>(this IReactiveCommand <T> source, CancellationToken cancellationToken = default(CancellationToken))
        {
            var tcs = new CancellableTaskCompletionSource <T>();

            var disposable = new SingleAssignmentDisposable();

            disposable.Disposable = source.Subscribe(x => {
                disposable.Dispose();                 // finish subscription.
                tcs.TrySetResult(x);
            }, ex => tcs.TrySetException(ex), () => tcs.TrySetCanceled());

            cancellationToken.Register(Callback, Tuple.Create(tcs, disposable.Disposable), false);

            return(tcs.Task);
        }
Exemple #4
0
        public static Task <T> WaitUntilValueChangedAsync <T>(this IReadOnlyReactiveProperty <T> source, CancellationToken cancellationToken = default(CancellationToken))
        {
            var tcs = new CancellableTaskCompletionSource <T>();

            var disposable = new SingleAssignmentDisposable();

            if (source.HasValue)
            {
                // Skip first value
                var isFirstValue = true;
                disposable.Disposable = source.Subscribe(x =>
                {
                    if (isFirstValue)
                    {
                        isFirstValue = false;
                        return;
                    }
                    else
                    {
                        disposable.Dispose(); // finish subscription.
                        tcs.TrySetResult(x);
                    }
                }, ex => tcs.TrySetException(ex), () => tcs.TrySetCanceled());
            }
            else
            {
                disposable.Disposable = source.Subscribe(x =>
                {
                    disposable.Dispose(); // finish subscription.
                    tcs.TrySetResult(x);
                }, ex => tcs.TrySetException(ex), () => tcs.TrySetCanceled());
            }

            cancellationToken.Register(Callback, Tuple.Create(tcs, disposable.Disposable), false);

            return(tcs.Task);
        }