// Chat - Multi-Spirit coordination
// All effects inferred from usage
gen ChatRoom {
has name: string
has message_count: Int
fun tick() {
if pending() > 0 {
let msg = recv()
let from = sender()
println("[" + this.name + "] " + from.to_string() + ": " + msg)
broadcast(msg)
this.message_count = this.message_count + 1
}
}
}
gen ChatUser {
has name: string
has room: SpiritId
fun say(msg: string) {
send(this.room, this.name + ": " + msg)
}
fun tick() {
if pending() > 0 {
let msg = recv()
println("[" + this.name + " sees] " + msg)
}
}
}