The example demonstrates the design of a chat application in five steps
- Declaring a Server
- Declaring a Client
- Declaring a message event on the Client and firing the event for every user input
- Declaring a publicMessage event on the Server aggregating all events from the clients
- Declaring a client-side observer for the server-side publicMessage event
@multitier object Chat {
trait Server extends Peer { type Tie <: Multiple[Client] }
}
trait Client extends Peer { type Tie <: Single[Server] }
val message = placed[Client] { Evt[String]() }
placed[Client].main {
for (line <- io.Source.stdin.getLines)
message fire line
}
val publicMessage = placed[Server] {
message.asLocalFromAllSeq map { case (_, message) => message }
}
publicMessage.asLocal observe println