コード例 #1
0
        private Task <T> RequestAsync <T>(PID target, object message, FutureProcess <T> future)
        {
            var messageEnvelope = new MessageEnvelope(message, future.Pid, null);

            SendUserMessage(target, messageEnvelope);
            return(future.Task);
        }
コード例 #2
0
ファイル: PID.cs プロジェクト: yubochinese/protoactor-dotnet
        /// <summary> PoisonAsync will tell and wait actor to stop after processing current user messages in mailbox. </summary>
        public Task PoisonAsync()
        {
            var future = new FutureProcess <object>();

            SendSystemMessage(new Watch(future.Pid));
            Poison();

            return(future.Task);
        }
コード例 #3
0
ファイル: PID.cs プロジェクト: ttallskog/protoactor-dotnet
        public Task <T> RequestAsync <T>(object message)
        {
            var tsc  = new TaskCompletionSource <T>();
            var reff = new FutureProcess <T>(tsc);
            var name = ProcessRegistry.Instance.NextId();

            var(pid, absent) = ProcessRegistry.Instance.TryAdd(name, reff);
            if (!absent)
            {
                throw new ProcessNameExistException(name);
            }
            Request(message, pid);
            return(tsc.Task);
        }
コード例 #4
0
        internal static async Task <T> RequestAsync <T>(this ISenderContext self, PID target, object message, CancellationToken cancellationToken)
        {
            using var future = new FutureProcess(self.System);
            var messageEnvelope = new MessageEnvelope(message, future.Pid);

            self.Send(target, messageEnvelope);
            var result = await future.GetTask(cancellationToken);

            switch (result)
            {
            case DeadLetterResponse:
                throw new DeadLetterException(target);

            case null:
            case T:
                return((T)result !);

            default:
                throw new InvalidOperationException(
                          $"Unexpected message. Was type {result.GetType()} but expected {typeof(T)}"
                          );
            }
        }
コード例 #5
0
 private Task <T> RequestAsync <T>(object message, FutureProcess <T> future)
 {
     Request(message, future.Pid);
     return(future.Task);
 }
コード例 #6
0
 private Task <T> RequestAsync <T>(PID target, object message, FutureProcess <T> future)
 {
     SendUserMessage(target, message, future.PID);
     return(future.Task);
 }