Exemplo n.º 1
0
 public CoalesceHandler(Func <TA, TA, TA> f, EventSink <TA> @out)
 {
     this.f    = f;
     this.@out = @out;
     Run       = (trans1, a) =>
     {
         if (accumValid)
         {
             accum = f(accum, a);
         }
         else
         {
             CoalesceHandler <TA> thiz = this;
             trans1.Prioritized(
                 @out.Node,
                 new Handler <Transaction>
             {
                 Run = trans2 =>
                 {
                     @out.Send(trans2, thiz.accum);
                     thiz.accumValid = false;
                     thiz.accum      = default(TA);
                 }
             });
             accum      = a;
             accumValid = true;
         }
     };
 }
Exemplo n.º 2
0
        Event <TA> Coalesce(Transaction trans1, Func <TA, TA, TA> f)
        {
            Event <TA> ev   = this;
            var        @out = new EventSink <TA>
            {
                SampleNow = () =>
                {
                    object[] oi = ev.SampleNow();
                    if (oi != null)
                    {
                        var o = (TA)oi[0];
                        for (int i = 1; i < oi.Length; i++)
                        {
                            o = f(o, (TA)oi[i]);
                        }
                        return(new object[] { o });
                    }
                    return(null);
                }
            };
            TransactionHandler <TA> h = new CoalesceHandler <TA>(f, @out);
            Listener l = Listen(@out.Node, trans1, h, false);

            return(@out.AddCleanup(l));
        }
Exemplo n.º 3
0
 public StreamSink(Func <T, T, T> coalesce)
 {
     this.coalescer = CoalesceHandler.CreateSafe(coalesce, this);
 }