/// <summary>
        /// Global watchdog worker.
        /// Acts as a heartbeat for any pending <see cref="InFlightRequest"/> in the locale queue,
        /// which waits the response within a certain timeout.
        /// </summary>
        private void WatchdogWorker()
        {
            while (this._watchdogCts.IsCancellationRequested == false)
            {
                if (Helpers.CancelableDelay(WatchdogClockInterval, this._watchdogCts.Token))
                {
                    //delay wa scanceled
                    break;
                }

                lock (this._reqlocker)
                {
                    foreach (var pair in this._requestRegister)
                    {
                        InFlightRequest request = pair.Value;
                        if (request.WatchdogClock(WatchdogClockInterval))
                        {
                            request.Reject(
                                new NATSTimeoutException("Timeout occurred while waiting for the reply.")
                                );
                        }
                    }
                }
            }
        }
 /// <summary>
 /// Removes the <see cref="InFlightRequest"/> from the local queue.
 /// </summary>
 /// <param name="request"></param>
 internal void DropRequest(InFlightRequest request)
 {
     lock (this._reqlocker)
     {
         this._requestRegister.Remove(request.ReqId);
     }
 }
        /// <summary>
        /// Common entry-point for all the "request" public synchronous methods
        /// </summary>
        /// <param name="message"></param>
        /// <param name="timeout"></param>
        /// <param name="token"></param>
        /// <returns></returns>
        private MsgOut RequestCore(
            MsgIn message,
            TimeSpan timeout,
            CancellationToken token
            )
        {
            InFlightRequest request = null;

            try
            {
                request = this._rrmgr.SetupRequest(message);
                this.PublishCore(message, timeout, token);
            }
            catch (Exception ex)
            {
                if (request != null)
                {
                    this._rrmgr.DropRequest(request);
                    request.Dispose();
                }
                throw ex;
            }

            return(request.GetReply(timeout, token));
        }
        /// <summary>
        /// Sets an <see cref="InFlightRequest"/> instance up,
        /// as proxy for a request-reply process.
        /// </summary>
        /// <param name="message"></param>
        /// <returns></returns>
        internal InFlightRequest SetupRequest(MsgIn message)
        {
            InFlightRequest request;

            lock (this._reqlocker)
            {
                request = new InFlightRequest(this, ++this._reqId);
                this._requestRegister.Add(request.ReqId, request);
            }

            message.InboxRequest = request;
            return(request);
        }