In this section, we go through a simple, working Hello World program. We will not go into too much, yet we will provide deeper information in the subsequent sections. For now, we will just define a reactor that waits for one incoming event, prints a message to the standard output once this event arrives, and then terminate.
We start by importing the contents of the io.reactors
package:
import io.reactors._
This allows us to use the facilities provided by the Reactors framework. In the following snippet, we declare a simple reactor-based program:
object ReactorHelloWorld { def main(args: Array[String]): Unit = { val welcomeReactor = Reactor[String] { self => self.main.events onEvent { name => println(s"Welcome, $name!") self.main.seal() } } val system = ReactorSystem.default("test-system") val ch = system.spawn(welcomeReactor) ch ! "Alan" } }
The program above declares an anonymous reactor called...