-
Notifications
You must be signed in to change notification settings - Fork 0
/
goal.omg
37 lines (31 loc) · 1.15 KB
/
goal.omg
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
// events are records that have some special static methods that allows for event handling.
event Hello{
String hello;
}
event World{
String world;
}
// run creates a new isolated runtime when an event is triggered.
// Main is an event that is triggered once when the application starts.
run (Main) {
// just need to decare some variables in this scope so they survive the async block.
String hello = "";
String world = "";
// async block allows for all expressions to be run at the same time.
// but will only exit the block when all expressions are completed.
async {
// next will pause execution until the next event of the type is emitted by someone.
hello = Hello.next().hello;
// since this is async block both next will pause at the same time.
world = World.next().world;
}
// We don't know if hello or world was set first but we know that both are set now.
printLine(hello + world);
}
run (Main){
// emit publishes a new event that may result in new runtime being spawned or other can query for.
Hello.emit(new Hello("Hello "));
}
run (Main){
World.emit(new World("world!"));
}