Пример #1
0
        /// <summary>
        ///     Posts a message to an agent and await a reply on the channel, synchronously.
        /// </summary>
        /// <param name="f">The lambda providing the message.</param>
        /// <returns>The agents reply</returns>
        public TReply PostAndReply(Func <AsyncReplyChannel <TReply>, TMessage> f)
        {
            var handle = new AsyncEventHandle <TReply>();

            Post(f(new AsyncReplyChannel <TReply>(handle.Complete)));
            handle.DoneEvent.WaitOne();
            return(handle.Result());
        }
Пример #2
0
 /// <summary>
 /// Starts a child computation. This allows multiple asynchronous computations to be executed simultaneously.
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="m"></param>
 /// <returns>A new computation that waits for the input computation to finish.</returns>
 public static Async <Async <T> > StartChild <T>(this Async <T> m)
 {
     return(() =>
     {
         var handle = new AsyncEventHandle <T>();
         m.StartAndReply(ch => new AsyncReplyChannel <T>(r =>
         {
             ch.Reply(r);
             handle.Complete(r);
             return Unit.Default;
         }));
         return () =>
         {
             handle.DoneEvent.WaitOne();
             return handle.Result();
         };
     });
 }