/// <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); } }
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); } }
/// <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); } }