コード例 #1
0
        public static IFuture <Y> SelectMany <X, Y>(this IFuture <X> @this, Func <X, IFuture <Y> > selector)
        {
            var outerSubscription = new SingleAssignmentDisposable();
            var innerSubscription = new SingleAssignmentDisposable();
            var promise           = new FutureBuilder <Y, ICancelable>(StableCompositeDisposable.Create(outerSubscription, innerSubscription));

            outerSubscription.Disposable =
                @this.Subscribe(
                    value =>
            {
                try
                {
                    innerSubscription.Disposable =
                        selector(value).Subscribe(
                            promise.Resolve,
                            promise.Reject
                            );
                }
                catch (Exception ex)
                {
                    promise.Reject(ex);
                }
            },
                    promise.Reject
                    );
            return(promise);
        }
コード例 #2
0
        public static IFuture <Y> Select <X, Y>(this IFuture <X> @this, Func <X, Y> selector)
        {
            var subscription = new SingleAssignmentDisposable();
            var promise      = new FutureBuilder <Y, SingleAssignmentDisposable>(subscription);

            subscription.Disposable =
                @this.Subscribe(
                    value => promise.Resolve(selector(value)),
                    promise.Reject
                    );

            return(promise);
        }