liminal-server 0.24.9

Standalone server for the liminal messaging bus
Documentation
//! A call tap is owned by its exact pending operation.

use super::{CallTrace, EntryState, Instant, PendingReplyTable};

impl PendingReplyTable {
    pub(in crate::server::connection) fn dispatched(&mut self, op_id: u64, at: Instant) {
        if let Some(entry) = self.entries.iter_mut().find(|entry| entry.op_id == op_id) {
            entry.dispatched_at = Some(at);
        }
    }

    /// The operation the next admission will own.
    pub(in crate::server::connection) const fn next_operation(&self) -> u64 {
        self.next_op_id
    }

    /// Binds the tap only after the route admitted and dispatched this operation.
    pub(in crate::server::connection) fn bind_tap(&mut self, op_id: u64, mut tap: CallTrace) {
        if let Some(entry) = self
            .entries
            .iter_mut()
            .find(|entry| entry.op_id == op_id && entry.state == EntryState::Pending)
        {
            if let Some(dispatched) = entry.dispatched_at {
                tap.dispatched_at(dispatched);
            }
            entry.tap = Some(tap);
        } else {
            tap.finish(
                crate::tap::TapOutcome::Refused,
                Some("call_not_pending"),
                Instant::now(),
            );
        }
    }

    /// Settles a worker's named refusal before cancelling its reservation.
    pub(in crate::server::connection) fn refuse(&mut self, op_id: u64, reason: &str) {
        if let Some(entry) = self.entries.iter_mut().find(|entry| entry.op_id == op_id)
            && let Some(tap) = entry.tap.take()
        {
            tap.finish(
                crate::tap::TapOutcome::Refused,
                Some(reason),
                Instant::now(),
            );
        }
        self.cancel(op_id);
    }
}