void McClientRequestContextBase::fireStateChangeCallbacks()

in mcrouter/lib/network/McClientRequestContext.cpp [24:62]


void McClientRequestContextBase::fireStateChangeCallbacks(
    ReqState old,
    ReqState current) const {
  if (!onStateChange_) {
    return;
  }

  int pending = 0;
  int inflight = 0;

  switch (old) {
    case ReqState::PENDING_QUEUE:
      pending--;
      break;
    case ReqState::WRITE_QUEUE:
    case ReqState::PENDING_REPLY_QUEUE:
    case ReqState::REPLIED_QUEUE:
      inflight--;
      break;
    default:
      break;
  }
  switch (current) {
    case ReqState::PENDING_QUEUE:
      pending++;
      break;
    case ReqState::WRITE_QUEUE:
    case ReqState::PENDING_REPLY_QUEUE:
    case ReqState::REPLIED_QUEUE:
      inflight++;
      break;
    default:
      break;
  }

  if (pending != 0 || inflight != 0) {
    onStateChange_(pending, inflight);
  }
}