Choreographic programming library for MoonBit.
Dependencies
moon add Milky2018/moonchortrait Location: Show + Hash {
name(Self) -> String
}
fn make_local_backend(
locations : Array[&Location],
logger~ : &Logger = make_mute_logger()
) -> Backend
async fn run_choreo[T, L : Location](
backend : Backend,
choreography : (ChoreoContext) -> T!Async,
role : L,
logger? : &Logger
) -> T struct Alice {}
struct Bob {}
impl Location for Alice with name(_) { "Alice" }
impl Location for Bob with name(_) { "Bob" }
let alice : Alice = Alice::{ }
let bob : Bob = Bob::{ }async fn simple_choreo(ctx: ChoreoContext) -> Unit {
let msg_at_alice = ctx.locally(alice, fn (_) { "Hello" })
let msg_at_bob = ctx.comm(alice, bob, msg_at_alice)
ctx.locally(bob, fn (unwrapper) { println(unwrapper.unwrap(msg_at_bob)) })
}let backend = make_local_backend([alice, bob])
run_choreo!(backend, simple_choreo, alice)
// or run_choreo!(backend, simple_choreo, bob)type Backendtype ChoreoContextasync fn[T : Message + ToJson + FromJson, L : Location + Show + Hash] ChoreoContext::announce(self : ChoreoContext, loc : L, targets : Array[&Location], located_value : Located[T, L], subchoreo : async (ChoreoContext, T) -> Unit) -> Unitasync fn[T : Message + ToJson + FromJson, L : Location + Show + Hash] ChoreoContext::broadcast(self : ChoreoContext, loc : L, value : Located[T, L]) -> Tasync fn ChoreoContext::enclave(self : ChoreoContext, locations : Array[&Location], subchoreo : async (ChoreoContext) -> Unit) -> Unitfn[T, L : Location + Show + Hash] ChoreoContext::locally(self : ChoreoContext, location : L, computation : (Unwrapper[L]) -> T) -> Located[T, L]async fn[T : Message + ToJson + FromJson, L : Location + Show + Hash] ChoreoContext::locally_broadcast(self : ChoreoContext, loc : L, computation : (Unwrapper[L]) -> T) -> Ttype Located[T, _]type Unwrapper[_]Choreographic programming library for MoonBit.
Dependencies