Sign in

    moonbitstack/moonzero/proc does not have a README file

    ShutdownCoordinator

    pub struct ShutdownCoordinator {
    shutting_down : Bool
    in_flight : Int
    }

    A graceful-shutdown coordinator for a zRPC server (← go-zero's proc.AddShutdownListener + gRPC's GracefulStop): once shutdown is initiated the server stops admitting new calls, but calls already in flight are allowed to run to completion. A call brackets its work between begin_call and end_call; begin_call returns false when the server is shutting down, which the transport surfaces as Unavailable — exactly the status a client sees once a server has stopped listening. The server is fully drained once shutdown has been initiated and no calls remain in flight.

    The counter is plain mutable state, which is safe under moonbitlang/async's cooperative single-threaded scheduling: begin_call/end_call never yield, so the count is only observed at await points between them.

    ShutdownCoordinator::begin_call

    fn ShutdownCoordinator::begin_call(self : ShutdownCoordinator) -> Bool

    Admit a new call: register it as in-flight and return true, unless shutdown has been initiated, in which case the call is refused (false) and the count is left untouched.

    ShutdownCoordinator::end_call

    fn ShutdownCoordinator::end_call(self : ShutdownCoordinator) -> Unit

    Mark an admitted call finished, dropping it from the in-flight count. Only call it for a call that begin_call admitted; the count never goes below zero.

    ShutdownCoordinator::in_flight

    fn ShutdownCoordinator::in_flight(self : ShutdownCoordinator) -> Int

    The number of calls currently in flight.

    ShutdownCoordinator::initiate_shutdown

    fn ShutdownCoordinator::initiate_shutdown(self : ShutdownCoordinator) -> Unit

    Begin the graceful shutdown: from now on begin_call refuses new calls while in-flight ones keep running. Idempotent.

    ShutdownCoordinator::is_drained

    fn ShutdownCoordinator::is_drained(self : ShutdownCoordinator) -> Bool

    Whether the server is fully drained: shutdown initiated and no call in flight. A supervisor loops on this (yielding between checks) to know the last in-flight RPC has finished and the process may exit.

    ShutdownCoordinator::is_shutting_down

    fn ShutdownCoordinator::is_shutting_down(self : ShutdownCoordinator) -> Bool

    Whether shutdown has been initiated.

    ShutdownCoordinator::new

    A coordinator that is serving normally with no calls in flight.

    Source Files