Exemple #1
0
        public static Promise <TResult> Select <TResult>(
            this Promise source, Func <object, TResult> selector)
        {
            if (source == null)
            {
                throw new ArgumentNullException(nameof(source));
            }
            if (selector == null)
            {
                throw new ArgumentNullException(nameof(selector));
            }

            return(source.Then((result, s) => selector(null)));
        }
Exemple #2
0
        public static Promise <TResult> SelectMany <TSource, TResult>(
            this Promise <TSource> source, Func <TSource, Promise <TResult> > selector)
        {
            if (source == null)
            {
                throw new ArgumentNullException(nameof(source));
            }
            if (selector == null)
            {
                throw new ArgumentNullException(nameof(selector));
            }

            return(source.Then((result, s) => selector(result)));
        }
Exemple #3
0
 public static Promise <T> Unwrap <T>(this Promise <Promise <T> > pipe)
 {
     if (pipe == null)
     {
         return(null);
     }
     return(new Promise <T>(pipe.CancelMode, (resolve, reject, onCancel) =>
     {
         onCancel(pipe.Cancel);
         pipe.Then((inner, s) => inner.Then((r, ss) => resolve(r, s && ss),
                                            (ex, ss) => reject(ex, s & ss))
                   .Cancelled(ex => reject(ex, s)), reject)
         .Cancelled(ex => reject(ex, true));
     }));
 }
Exemple #4
0
        public static Promise <TSource> Where <TSource>(
            this Promise <TSource> source, Func <TSource, bool> predicate)
        {
            if (source == null)
            {
                throw new ArgumentNullException(nameof(source));
            }
            if (predicate == null)
            {
                throw new ArgumentNullException(nameof(predicate));
            }

            return(source.Then((result, s) => {
                if (predicate(result))
                {
                    return result;
                }
                throw new CancelledException();
            }));
        }
Exemple #5
0
        public static Promise <TResult> SelectMany <TSource, TCollection, TResult>(
            this Promise <TSource> source,
            Func <TSource, Promise <TCollection> > collectionSelector,
            Func <TSource, TCollection, TResult> resultSelector)
        {
            if (source == null)
            {
                throw new ArgumentNullException(nameof(source));
            }
            if (collectionSelector == null)
            {
                throw new ArgumentNullException(nameof(collectionSelector));
            }
            if (resultSelector == null)
            {
                throw new ArgumentNullException(nameof(resultSelector));
            }

            return(source.Then((result, s) => collectionSelector(result)
                               .Then((collection, ss) => resultSelector(result, collection))));
        }
Exemple #6
0
        public static Promise <TResult> GroupJoin <TOuter, TInner, TKey, TResult>(
            this Promise <TOuter> outer, Promise <TInner> inner,
            Func <TOuter, TKey> outerKeySelector,
            Func <TInner, TKey> innerKeySelector,
            Func <TOuter, Promise <TInner>, TResult> resultSelector,
            IEqualityComparer <TKey> comparer)
        {
            if (outer == null)
            {
                throw new ArgumentNullException(nameof(outer));
            }
            if (inner == null)
            {
                throw new ArgumentNullException(nameof(inner));
            }
            if (outerKeySelector == null)
            {
                throw new ArgumentNullException(nameof(outerKeySelector));
            }
            if (innerKeySelector == null)
            {
                throw new ArgumentNullException(nameof(innerKeySelector));
            }
            if (resultSelector == null)
            {
                throw new ArgumentNullException(nameof(resultSelector));
            }
            if (comparer == null)
            {
                throw new ArgumentNullException(nameof(comparer));
            }

            return(outer.Then((outResult, s) => inner.Then((inResult, ss) => {
                if (comparer.Equals(outerKeySelector(outResult), innerKeySelector(inResult)))
                {
                    return resultSelector(outResult, inner);
                }
                throw new CancelledException();
            })));
        }
Exemple #7
0
 public static Promise <T> Resolved <T>(Promise <T> promise)
 {
     return(new Promise <T>((resolve, reject) => promise.Then(resolve, reject)));
 }
Exemple #8
0
 public static Promise <object> Resolved(Promise promise)
 {
     return(new Promise <object>((resolve, reject) =>
                                 promise.Then((r, s) => resolve(r, s), reject)));
 }