예제 #1
0
 public static Func <T, IPromise> ReturnPromise <T>(this Action <T> fn, PromiseFactory factory)
 {
     return(x =>
     {
         fn(x);
         return factory.Value();
     });
 }
예제 #2
0
 public static Func <IPromise> ReturnPromise(this Action fn, PromiseFactory factory)
 {
     return(() =>
     {
         fn();
         return factory.Value();
     });
 }
예제 #3
0
        public static IPromise <T> UnCast <T>(this IPromise p, PromiseFactory factory, T defaultValue)
        {
            if (p == null)
            {
                return(factory.Value(defaultValue));
            }

            return(p.Then(() => defaultValue));
        }
예제 #4
0
        public IntervalHandleImpl(PromiseFactory factory, int timeout, Action action, PromisePriority priority)
        {
            var x = new BackboneIntervalHandleImpl <IntervalHandleImpl>(this, factory, timeout, () =>
            {
                action();
                return(factory.Value <object>(null));
            }, priority);

            x.Start();

            _base = x;
        }
예제 #5
0
        internal void Next(Func <IPromise <ControlValue <T> > > action)
        {
            lock (this)
            {
                if (_last == null)
                {
                    _last = action();
                }
                else
                {
                    _last = _last.Then(value =>
                    {
                        if (value == null || value.State != ControlState.Next)
                        {
                            return(_factory.Value(value));
                        }

                        return(action());
                    });
                }
            }
        }
예제 #6
0
        private static IPromise <IPromiseEnumerator <Tuple <Key, Value> > > OrderByInternal <Key, Value>
            (PromiseFactory factory, IPromiseEnumerator <Tuple <Key, Value> > items, int count, IComparer <Key> comparer)
        {
            if (count < 2)
            {
                return(factory.Value(items));
            }

            int at = count / 2;

            return(OrderByInternal(factory, TakeWhileEnumerator.Create(items, at), at, comparer).Then(firstPart =>
                                                                                                      items.Advance(at).Then(half => OrderByInternal(factory, half, count - at, comparer)).Then(secondPart =>
                                                                                                                                                                                                (IPromiseEnumerator <Tuple <Key, Value> >)
                                                                                                                                                                                                new MergeEnumerator <Key, Value>(factory, new NullableResult <Tuple <Key, Value> >(), comparer, firstPart, secondPart))));
        }
예제 #7
0
        public static IPromise <NullableResult <T> > ToNullableResult <T>(this IPromise <ControlValue <T> > p, PromiseFactory factory)
        {
            if (p == null)
            {
                return(factory.Value(new NullableResult <T>()));
            }

            return(p.Then(result =>
            {
                if (result == null || result.State != ControlState.Return || !result.HasValue)
                {
                    return new NullableResult <T>();
                }

                return new NullableResult <T>(result.Value);
            }));
        }
예제 #8
0
        public static IPromise <ControlState> ToControlState <T>(this IPromise <ControlValue <T> > p, PromiseFactory factory)
        {
            if (p == null)
            {
                return(factory.Value(ControlState.Next));
            }

            return(p.Then(result =>
            {
                if (result == null)
                {
                    return ControlState.Next;
                }

                return result.State;
            }));
        }
예제 #9
0
 public static IPromise <E> SafeThen <T, E>(this PromiseFactory factory, IPromise <T> next, Func <T, E> conusmer)
 {
     return(factory.SafeThen(next, x => factory.Value(conusmer(x))));
 }
예제 #10
0
 public static Func <T, IPromise <ControlValue <object> > > Canonical <T>(this PromiseFactory factory, Func <T, ControlState> fn)
 {
     return(factory.Canonical <T, object>(x => factory.Value(fn(x))));
 }
예제 #11
0
 public static Func <T, IPromise <ControlValue <E> > > Canonical <T, E>(this PromiseFactory factory, Func <T, E> fn)
 {
     return(factory.Canonical <T, E>(x => factory.Value(fn(x))));
 }
예제 #12
0
 public static Func <IPromise <ControlValue <T> > > Canonical <T>(this PromiseFactory factory, Func <ControlState> fn)
 {
     return(factory.Canonical <T>(() => factory.Value(fn())));
 }
예제 #13
0
 public static Func <IPromise <ControlValue <T> > > Canonical <T>(this PromiseFactory factory, Func <NullableResult <T> > fn)
 {
     return(factory.Canonical(() => factory.Value(fn())));
 }
예제 #14
0
 public static IPromise <T> SafeThen <T>(this PromiseFactory factory, IPromise next, Func <T> conusmer)
 {
     return(factory.SafeThen(next, () => factory.Value(conusmer())));
 }