Sign in

    moon-lander-actors

    Local typed actors with bounded mailboxes for the Moon-Lander framework

    Download zip
    Author
    Version
    0.8.0
    License
    Apache-2.0
    Last updated
    7 hours ago
    Downloads
    5

    #Actors

    moonrockz/moon-lander-actors gives local typed actors: units that own private state and one mailbox and handle one message at a time. A scope owns each actor's lifetime. No actor system, registry or host is necessary.

    The module has two packages:

    PackageAliasTargetsContents
    moonrockz/moon-lander-actors@policywasm, wasm-gc, js, nativeChecked policy values: MailboxCapacity, MessageCount, MailboxPolicy, Admission
    moonrockz/moon-lander-actors/runtime@actorswasm, js, nativeScopes, actors, references, replies and Receive values. See the runtime guide

    The module imports only moonrockz/moon-lander-core and moonbitlang/async. It does not depend on hosting, configuration, mediator or logging, and the umbrella module does not import it.

    graph LR core[moon-lander-core] --> policy["actors (policy, portable)"] policy --> runtime["actors/runtime"] async[moonbitlang/async] --> runtime

    Each mbt check block on this page runs as a test with mise run test on all four targets.

    #Checked policy values

    A mailbox capacity and a message count are positive numbers from one to the largest Int. Their constructors are the only way to make them, and they raise a typed CountError that holds the input and the broken rule.

    ///|
    test "a capacity is positive" {
    assert_eq(@policy.MailboxCapacity::from_int(1).to_int(), 1)
    let rejected = try {
    ignore(@policy.MailboxCapacity::from_int(0))
    None
    } catch {
    InvalidCapacity(input~, rule=NotPositive) => Some(input)
    InvalidCount(..) => None
    }
    assert_eq(rejected, Some(0))
    }

    The default mailbox policy is bounded at 128 queued messages. An unbounded mailbox is an explicit choice:

    ///|
    test "the default policy is bounded at 128" {
    guard @policy.MailboxPolicy::default() is Bounded(capacity) else {
    fail("the default is unbounded")
    }
    assert_eq(capacity.to_int(), 128)
    assert_true(@policy.MailboxPolicy::Unbounded != @policy.MailboxPolicy::default())
    }

    CountError

    pub suberror CountError {
    InvalidCapacity(input~ : Int, rule~ : CountRule)
    InvalidCount(input~ : Int, rule~ : CountRule)
    } derive(
    Debug
    )

    An input that is not a valid mailbox capacity or message count. Only the constructors of MailboxCapacity and MessageCount make these errors.

    NameError

    pub suberror NameError {
    InvalidName(input~ : String, rule~ : NameRule)
    } derive(
    Debug
    )

    An input that is not a valid actor name. Only ActorName::parse makes it.

    ActorName

    pub struct ActorName {
    // private fields
    } derive(Eq, Hash,
    Debug
    )

    A label that an actor scope can reserve for one actor at a time: 1 to 128 ASCII characters, a letter first, then letters, digits, _, - or .. Names are case sensitive and are not trimmed or normalized.

    ActorName::equal

    fn ActorName::equal(ActorName, ActorName) -> Bool

    ActorName::hash

    fn ActorName::hash(self : ActorName) -> Int

    ActorName::hash_combine

    fn ActorName::hash_combine(ActorName, Hasher) -> Unit

    ActorName::not_equal

    fn ActorName::not_equal(x : ActorName, y : ActorName) -> Bool

    ActorName::parse

    fn ActorName::parse(text : String) -> ActorName raise NameError

    Parse text as an actor name.

    ActorName::to_string

    fn ActorName::to_string(self : ActorName) -> String

    The name as it was parsed.

    Admission

    pub(all) enum Admission {
    Accepted
    Full
    Closed
    } derive(Eq,
    Debug
    )

    The result of a send that does not wait.

    Admission::equal

    fn Admission::equal(Admission, Admission) -> Bool

    Admission::not_equal

    fn Admission::not_equal(x : Admission, y : Admission) -> Bool

    CountRule

    pub enum CountRule {
    NotPositive
    } derive(Eq,
    Debug
    )

    The rule of a positive count that an input breaks.

    CountRule::equal

    fn CountRule::equal(CountRule, CountRule) -> Bool

    CountRule::not_equal

    fn CountRule::not_equal(x : CountRule, y : CountRule) -> Bool

    MailboxCapacity

    pub struct MailboxCapacity {
    // private fields
    } derive(Eq, Hash,
    Debug
    )

    The largest number of queued messages that a bounded mailbox holds, from 1 to the largest Int. The in-flight message does not count.

    MailboxCapacity::default

    The default capacity: 128 queued messages.

    MailboxCapacity::equal

    MailboxCapacity::from_int

    fn MailboxCapacity::from_int(count : Int) -> MailboxCapacity raise CountError

    Make a capacity of count queued messages.

    MailboxCapacity::hash

    fn MailboxCapacity::hash(self : MailboxCapacity) -> Int

    MailboxCapacity::hash_combine

    fn MailboxCapacity::hash_combine(MailboxCapacity, Hasher) -> Unit

    MailboxCapacity::not_equal

    fn MailboxCapacity::not_equal(x : MailboxCapacity, y : MailboxCapacity) -> Bool

    MailboxCapacity::to_int

    fn MailboxCapacity::to_int(self : MailboxCapacity) -> Int

    The capacity as a count of messages, from 1 to the largest Int.

    MailboxPolicy

    pub(all) enum MailboxPolicy {
    Bounded(MailboxCapacity)
    Unbounded
    } derive(Eq,
    Debug
    )

    How many queued messages a mailbox can hold.

    MailboxPolicy::default

    fn MailboxPolicy::default() -> MailboxPolicy

    The default policy: bounded at MailboxCapacity::default().

    MailboxPolicy::equal

    MailboxPolicy::not_equal

    fn MailboxPolicy::not_equal(x : MailboxPolicy, y : MailboxPolicy) -> Bool

    MessageCount

    pub struct MessageCount {
    // private fields
    } derive(Eq, Hash,
    Debug
    )

    The largest number of messages that a finite receive takes, from 1 to the largest Int.

    MessageCount::equal

    MessageCount::from_int

    fn MessageCount::from_int(count : Int) -> MessageCount raise CountError

    Make a count of count messages.

    MessageCount::hash

    fn MessageCount::hash(self : MessageCount) -> Int

    MessageCount::hash_combine

    fn MessageCount::hash_combine(MessageCount, Hasher) -> Unit

    MessageCount::not_equal

    fn MessageCount::not_equal(x : MessageCount, y : MessageCount) -> Bool

    MessageCount::to_int

    fn MessageCount::to_int(self : MessageCount) -> Int

    The count as an Int, from 1 to the largest Int.

    NameRule

    pub enum NameRule {
    Empty
    TooLong
    FirstNotLetter(Char)
    InvalidCharacter(Char)
    } derive(Eq,
    Debug
    )

    The rule of an actor name that an input breaks.

    NameRule::equal

    fn NameRule::equal(NameRule, NameRule) -> Bool

    NameRule::not_equal

    fn NameRule::not_equal(x : NameRule, y : NameRule) -> Bool

    NameRule::to_repr

    Powered by MoonBit

    Site sourceReport issuePackagesBuild queueSkillsStatistics

    © 2026 mooncakes.io