Exemplo n.º 1
0
 public ExtWire()
 {
     Connected.WhenTrue(Lifetime.Eternal, _ =>
     {
         lock (mySendQ)
         {
             while (mySendQ.Count > 0)
             {
                 var p = mySendQ.Dequeue();
                 RealWire.Send(p.Key, writer => writer.WriteRaw(p.Value));
             }
         }
     });
 }
Exemplo n.º 2
0
        internal Lifetime Subscribe(Lifetime outerLifetime)
        {
            var taskWireSubscriptionDefinition = outerLifetime.CreateNested();
            var externalCancellation           = outerLifetime.CreateNested();

            myCall.Wire.Advise(taskWireSubscriptionDefinition.Lifetime, this); //this lifetimeDef listen only one value
            taskWireSubscriptionDefinition.Lifetime.TryOnTermination(() => ResultInternal.SetIfEmpty(RdTaskResult <TRes> .Cancelled()));

            Result.AdviseOnce(Lifetime.Eternal, taskResult =>
            {
                try
                {
                    var potentiallyBindable = taskResult.Result;
                    if (potentiallyBindable.IsBindable())
                    {
                        if (myIsEndpoint)
                        {
                            potentiallyBindable.IdentifyPolymorphic(myCall.Proto.Identities, myCall.RdId.Mix(RdId.ToString()));
                        }

                        potentiallyBindable.BindPolymorphic(externalCancellation.Lifetime, myCall, RdId.ToString());
                    }
                    else
                    {
                        externalCancellation.Terminate();
                    }

                    if (myIsEndpoint)
                    {
                        Trace(RdReactiveBase.ourLogSend, "send response", taskResult);
                        myWire.Send(RdId,
                                    writer =>
                        {
                            RdTaskResult <TRes> .Write(myCall.WriteResponseDelegate, myCall.SerializationContext, writer, taskResult);
                        });
                    }
                    else if (taskResult.Status == RdTaskStatus.Canceled) //we need to transfer cancellation to the other side
                    {
                        Trace(RdReactiveBase.ourLogSend, "send cancellation");
                        myWire.Send(RdId, writer => { writer.Write(Unit.Instance); }); //send cancellation to the other side
                    }
                }
                finally
                {
                    taskWireSubscriptionDefinition.Terminate(); //no need to listen result or cancellation from wire
                }
            });

            return(externalCancellation.Lifetime);
        }
Exemplo n.º 3
0
 private void SendState(IWire parentWire, ExtState state)
 {
     parentWire.Send(RdId, writer =>
     {
         SendTrace?.Log($"{this} : {state}");
         writer.Write((int)state);
         writer.Write(SerializationHash);
     });
 }
Exemplo n.º 4
0
 private void SendState(IWire parentWire, ExtState state)
 {
     parentWire.Send(RdId, writer =>
     {
         TraceMe(LogSend, state);
         writer.Write((int)state);
         writer.Write(SerializationHash);
     });
 }
Exemplo n.º 5
0
 private void SendState(IWire parentWire, ExtState state)
 {
     using (base.Proto.Contexts.CreateSendWithoutContextsCookie())
         parentWire.Send(RdId, writer =>
         {
             SendTrace?.Log($"{this} : {state}");
             writer.Write((int)state);
             writer.Write(SerializationHash);
         });
 }
Exemplo n.º 6
0
        public WiredRdTask(LifetimeDefinition lifetimeDef, RdCall <TReq, TRes> call, RdId rdId, IScheduler scheduler)
        {
            myLifetimeDef = lifetimeDef;
            myCall        = call;
            RdId          = rdId;
            Scheduler     = scheduler;
            myWire        = call.Wire;

            call.Wire.Advise(lifetimeDef.Lifetime, this);
            lifetimeDef.Lifetime.TryOnTermination(() =>
            {
                //otherwise it could be successful continuation from Queue
                if (ResultInternal.SetIfEmpty(RdTaskResult <TRes> .Cancelled()))
                {
                    RdReactiveBase.LogSend.Trace($"call {myCall.Location} ({myCall.RdId}) send cancellation for task '{RdId}'");
                    myWire.Send(rdId, writer => { writer.Write(Unit.Instance); }); //send cancellation to the other side
                }
            });
        }
Exemplo n.º 7
0
 public static void Send(this IWire wire, RdId id, Action <UnsafeWriter> writer)
 {
     wire.Send(id, writer, (action, w) => action(w));
 }
Exemplo n.º 8
0
Arquivo: WireEx.cs Projeto: epeshk/rd
 public static void Send(this IWire wire, RdId id, Action <UnsafeWriter> writer)
 {
     wire.Send(id, (object)null, (_, w) => writer(w));
 }