moonbitstack/moonzero/balance does not have a README file

    Resolve

    type Resolve = (String) -> Array[
    Endpoint
    ]

    The instances of a service. It runs on every call, so it must answer without waiting: a program passes @moonsd.View::endpoints here and runs View::follow in a task of its own.

    Balancer

    pub(all) enum Balancer {
    RoundRobin(
    RoundRobin
    )
    PickFirst
    Weighted(
    Weighted
    )
    }

    How a load-balanced channel chooses: in turn, in proportion to Endpoint::weight, or always the first (gRPC's pick_first). Weighted keeps its credit by Endpoint::id.

    Balancer::pick

    One of endpoints, or None if there is nothing to choose.

    Balancer::round_robin

    fn Balancer::round_robin() -> Balancer

    Instances in turn, from the first.

    Balancer::weighted

    fn Balancer::weighted() -> Balancer

    Instances by weight, with no credit yet.

    LoadBalancedChannel

    pub struct LoadBalancedChannel {
    resolve : (String) -> Array[
    Endpoint
    ]
    cluster : RpcCluster
    balancer : Balancer
    service : String
    }

    A load-balanced zRPC client (← go-zero's zrpc.Client over a discovery target): it resolves a service through Resolve, picks a live instance with the Balancer, dials it on the RpcCluster, and makes the call. The whole resolve→balance→dial→call path runs per call, so instances registering or deregistering between calls take effect on the next one.

    LoadBalancedChannel::call

    fn LoadBalancedChannel::call(self : LoadBalancedChannel, path : String, request : Bytes) -> Result[Bytes,
    Status
    ] raise

    Make a unary call to path, resolving and balancing to a live instance first.

    LoadBalancedChannel::call_bidi_streaming

    fn LoadBalancedChannel::call_bidi_streaming(self : LoadBalancedChannel, path : String, requests : Array[Bytes]) -> Result[Array[Bytes],
    Status
    ] raise

    Make a bidirectional-streaming call to path, resolving and balancing to a live instance first, then driving the whole requests exchange to completion.

    LoadBalancedChannel::call_server_streaming

    fn LoadBalancedChannel::call_server_streaming(self : LoadBalancedChannel, path : String, request : Bytes) -> Result[Array[Bytes],
    Status
    ] raise

    Make a server-streaming call to path, resolving and balancing to a live instance first.

    LoadBalancedChannel::new

    fn LoadBalancedChannel::new(resolve : (String) -> Array[
    Endpoint
    ], cluster : RpcCluster, service : String, balancer? : Balancer) -> LoadBalancedChannel

    Build a load-balanced channel for service over a Resolve interface, dialing through cluster with balancer (round-robin by default).

    RpcCluster

    pub struct RpcCluster {
    servers : Map[String,
    RpcServer
    ]
    }

    The in-process dial table: an endpoint address maps to the RpcServer listening there. It stands in for DNS resolution plus a socket dial in the in-process h2c transport — a real deployment opens a connection to the address instead of looking the server up here, but the resolve→balance→call path above it is the same.

    RpcCluster::add

    Bind the server reachable at endpoint's address.

    RpcCluster::dial

    Open a channel to the server bound at endpoint, or None if nothing is reachable there (a stale registry entry pointing at a gone instance).

    RpcCluster::new

    fn RpcCluster::new() -> RpcCluster

    An empty cluster.

    Source Files

    Powered by MoonBit

    Site sourceReport issueModulesSkillsBuild queueStatistics

    © 2026 mooncakes.io