Esempio n. 1
0
        public PostedMessage <T> Fanout()
        {
            var fanout = new PostedMessage <T> {
                Argument = this.Argument
            };

            _fanoutTasks.Add(fanout._completion.Task);
            return(fanout);
        }
Esempio n. 2
0
 public void Post(PostedMessage <T> message)
 {
     Context.StartNew(() =>
     {
         try
         {
             Handler.Invoke(null, message.Argument);
             message.Complete();
         }
         catch (Exception ex)
         {
             message.MarkError(ex);
         }
     });
 }
Esempio n. 3
0
        private static async Task PostToEventSource <T>(T obj, EventRegistrationTokenTable <EventHandler <PostedMessage <T> > > eventSource)
        {
            PostedMessage <T> message = new PostedMessage <T> {
                Argument = obj
            };
            await Task.Run(() =>
            {
                // If we have delegates bound to the event source, each one
                // will get a fanned out PostedMessage. They will all get aggregated
                // and returned via GetAggregatedTask() below.
                eventSource.InvocationList?.Invoke(null, message);

                // And mark the "parent" PostedMessage as being completed. This
                // also handles the case of not having any delegates bound to the
                // invocation list.
                message.Complete();
            });

            await message.GetAggregatedTask();
        }