Beispiel #1
0
 public static Await <Empty> Take <T>(this Await <T> source, Action <T> take)
 {
     return(source.Map(result =>
     {
         take(result);
         return Empty.Value;
     }));
 }
Beispiel #2
0
 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)));
 }
Beispiel #3
0
        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))));
        }
Beispiel #4
0
 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));
         }
     }));
 }
Beispiel #5
0
        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> >());
        }
Beispiel #6
0
 internal Awaiting(Await <Empty> proceed)
 {
     _proceed = proceed;
 }
Beispiel #7
0
 public static T WaitSuccess <T>(this Await <T> source, int timeoutMilliseconds = Timeout.Infinite)
 {
     return(source.Wait(timeoutMilliseconds).Some.Success);
 }
Beispiel #8
0
 public static Cancelable Start <T>(this Await <T> source)
 {
     return(source(ignoredResult => { }));
 }