// If there are no inflight requests, sends the request right away. // Otherwise puts it in a queue. When the current inflight request finishes, // the next one will be sent. // Inflight requests finish either when OnReply() is called or they time out. public void Send(Resp msg, Action <TimestampedMsg <Req> > done) { DateTime deadline = DateTime.UtcNow + RequestTimeout; _queue.Send(() => TrySend(msg, deadline, done), deadline, (bool success) => { if (!success) { _log.Warn("Unable to send request to the exchange: timed out in Turnstile."); done.Invoke(null); } }); }
// `OnMessage` may trigger before `done(true)`. public void SendAsync(Out msg, DateTime deadline, Action <bool> done) { Func <bool> request = () => { using (IWriter <Out> writer = TryLock()) { if (writer == null) { return(false); } writer.Send(msg); return(true); } }; _requestQueue.Send(request, deadline, done); }