Debian Codegraph @

examples/book/digital-artists/chapter10/Listing10.3.ck

raw
1 // Listing 10.3 Simple event signaling
2
3 // Declare an event we will use for signaling
4 Event evnt; // (1) Declare an event object.
5
6 // function that waits on an event
7 fun void foo( Event anEvent)
8 { // (2) Declare a function to wait on any event.
9 Impulse imp => dac; // (3) Sonify the function with a click.
10 while( true ) // (4) Infinite loop.
11 {
12 // wait
13 anEvent => now; // (5) Wait on event...
14
15 // action // (6) when event is sent,
16 <<< "Hey!!!", now / second >>>; // print out...
17 5 => imp.next; // (7) and make click.
18 }
19 }
20
21 // spork a foo
22 spork ~ foo( evnt ); // (8) To test, spork your event-waiting function.
23
24 // then signal the event forever in a loop
25 while( true ) // (9) Infinite loop...
26 {
27 // fire the next signal
28 evnt.signal(); // (10) ...to signal the event...
29 // advance time
30 1::second => now; // (11) ...every second.
31 }