public static Await <Empty> Take <T>(this Await <T> source, Action <T> take) { return(source.Map(result => { take(result); return Empty.Value; })); }
public static Cancelable Match <T>( this Await <T> source, Action <T> success = null, Action <Exception> failure = null, Action cancel = null, Action <Result <T> > result = null) { return(source(opt => opt.Match(result ?? (r => r.Match(success, failure)), cancel))); }
public static Await <R> Many <T1, T2, R>( Await <T1> source1, Await <T2> source2, R defaultResult, Func <Optional <Result <T1> >, Optional <Result <T2> >, Optional <R> > choose) { var result1 = None.Of <Result <T1> >(); var result2 = None.Of <Result <T2> >(); return(Many( (_, i) => choose(result1, result2), defaultResult, source1.Take(result => result1 = Success.Of(result)), source2.Take(result => result2 = Success.Of(result)))); }
public static Await <R> Map <T, R>(this Await <T> source, Func <T, R> map) { return(complete => source(result => { if (result.IsNone) { complete(None.Of <Result <R> >()); } else if (result.Some.IsError) { complete(Error.Of <R>(result.Some.Error)); } else { var converted = Try.Do(() => map(result.Some.Success)); complete(converted.IsSuccess ? Success.Of(converted.Success) : Error.Of <R>(converted.Error)); } })); }
public static Optional <Result <T> > Wait <T>(this Await <T> source, int timeoutMilliseconds = Timeout.Infinite) { var completed = new AutoResetEvent(false); var result = None.Of <Result <T> >(); var cancel = source(x => { result = x; completed.Set(); }); if (completed.WaitOne(timeoutMilliseconds)) { return(result); } cancel(); return(None.Of <Result <T> >()); }
internal Awaiting(Await <Empty> proceed) { _proceed = proceed; }
public static T WaitSuccess <T>(this Await <T> source, int timeoutMilliseconds = Timeout.Infinite) { return(source.Wait(timeoutMilliseconds).Some.Success); }
public static Cancelable Start <T>(this Await <T> source) { return(source(ignoredResult => { })); }