public EnqueueComputation(Async <Unit> computation)
 {
     Computation = computation;
 }
Пример #2
0
 /// <summary>
 /// When computation completes successfully returns Either.Success with the returned value, otherwise Either.Failure with the exception.
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="m"></param>
 /// <returns></returns>
 public static Async <Either <T, Exception> > Catch <T>(this Async <T> m)
 {
     return(() => Either.Catch <T>(m.RunSynchronously));
 }
 public Unit Enqueue(Async <Unit> a)
 {
     return(Agent.Post(new EnqueueComputation(a)));
 }
Пример #4
0
 /// <summary>
 /// Starts the asynchronous computation in the thread pool. Do not await its result.
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="m"></param>
 /// <returns></returns>
 public static Unit Start <T>(this Async <T> m)
 {
     return(ComputationQueue.Enqueue(m.Ignore()));
 }
Пример #5
0
 /// <summary>
 /// Runs the provided asynchronous computation and awaits its result.
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="m"></param>
 /// <returns></returns>
 public static T RunSynchronously <T>(this Async <T> m)
 {
     return(m.Invoke());
 }
Пример #6
0
        // Functor functions

        /// <summary>
        /// Applies f to the result of m
        /// </summary>
        /// <typeparam name="TInput"></typeparam>
        /// <typeparam name="TOutput"></typeparam>
        /// <param name="m"></param>
        /// <param name="f"></param>
        /// <returns></returns>
        public static Async <TOutput> Map <TInput, TOutput>(this Async <TInput> m, Func <TInput, TOutput> f)
        {
            return(m.Bind <TInput, TOutput>(v => () => f(v)));
        }
Пример #7
0
 /// <summary>
 /// Runs m then returns h
 /// </summary>
 /// <typeparam name="TInput"></typeparam>
 /// <typeparam name="TOutput"></typeparam>
 /// <param name="m"></param>
 /// <param name="h"></param>
 /// <returns></returns>
 public static Async <TOutput> Then <TInput, TOutput>(this Async <TInput> m, Async <TOutput> h)
 {
     return(m.Bind(_ => h));
 }
Пример #8
0
 /// <summary>
 /// Applies f to the result of m
 /// </summary>
 /// <typeparam name="TInput"></typeparam>
 /// <typeparam name="TOutput"></typeparam>
 /// <param name="m"></param>
 /// <param name="f"></param>
 /// <returns></returns>
 public static Async <TOutput> Bind <TInput, TOutput>(this Async <TInput> m, Func <TInput, Async <TOutput> > f)
 {
     return(() => f(m.RunSynchronously()).RunSynchronously());
 }