예제 #1
0
        /// <summary>
        /// Send the specified message.
        /// </summary>
        /// <returns>The send.</returns>
        /// <param name="message">Message.</param>
        public Task <NngResult <T> > Send(T message)
        {
            lock (sync)
            {
                CheckState();

                State = AsyncState.Send;
                tcs   = Extensions.CreateSource <T>();
                Aio.SetMsg(Factory.Take(ref message));
                Ctx.Send(Aio);
                return(tcs.Task);
            }
        }
예제 #2
0
        public Task <NngResult <Unit> > Send(T message)
        {
            lock (sync)
            {
                CheckState();

                sendTcs = Extensions.CreateSendResultSource();
                State   = AsyncState.Send;
                Aio.SetMsg(Factory.Take(ref message));
                socket.Send(Aio);
                return(sendTcs.Task);
            }
        }
예제 #3
0
 /// <summary>
 /// Reply with the specified message.
 /// </summary>
 /// <returns>The reply.</returns>
 /// <param name="message">Message.</param>
 public Task <NngResult <Unit> > Reply(T message)
 {
     lock (sync)
     {
         System.Diagnostics.Debug.Assert(State == AsyncState.Wait);
         State = AsyncState.Send;
         // Save response TCS here to avoid race where send completes and asyncMessage replaced before we
         // can return it
         var ret = asyncMessage.replyTcs.Task;
         Aio.SetMsg(Factory.Take(ref message));
         Ctx.Send(Aio);
         return(ret);
     }
 }