public static Func <T, IPromise> ReturnPromise <T>(this Action <T> fn, PromiseFactory factory) { return(x => { fn(x); return factory.Value(); }); }
public static Func <IPromise> ReturnPromise(this Action fn, PromiseFactory factory) { return(() => { fn(); return factory.Value(); }); }
public static IPromise <T> UnCast <T>(this IPromise p, PromiseFactory factory, T defaultValue) { if (p == null) { return(factory.Value(defaultValue)); } return(p.Then(() => defaultValue)); }
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; }
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()); }); } } }
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)))); }
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); })); }
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; })); }
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)))); }
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)))); }
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)))); }
public static Func <IPromise <ControlValue <T> > > Canonical <T>(this PromiseFactory factory, Func <ControlState> fn) { return(factory.Canonical <T>(() => factory.Value(fn()))); }
public static Func <IPromise <ControlValue <T> > > Canonical <T>(this PromiseFactory factory, Func <NullableResult <T> > fn) { return(factory.Canonical(() => factory.Value(fn()))); }
public static IPromise <T> SafeThen <T>(this PromiseFactory factory, IPromise next, Func <T> conusmer) { return(factory.SafeThen(next, () => factory.Value(conusmer()))); }