Debian Codegraph @

examples/book/digital-artists/chapter10/Listing10.4c.ck

raw
1 // Listing 10.4c Using one shred to signal() multiple other shreds
2
3 // Declare an event we will use for signaling
4 Event evnt;
5
6 // function that waits on an event
7 fun void bar(Event anEvent, string msg, float freq)
8 {
9 Impulse imp => ResonZ rez => dac;
10 50 => rez.Q;
11 while( true )
12 {
13 // wait
14 anEvent => now;
15 // action
16 <<< msg, freq, now / second >>>;
17 freq => rez.freq;
18 50 => imp.next;
19 }
20 }
21
22 // spork a few bar shreds
23 spork ~ bar( evnt, "Hi ", 500.0 );
24 spork ~ bar( evnt, "There ", 700.0 );
25 spork ~ bar( evnt, "Sport! ", 900.0 );
26
27 // then signal the event forever in a loop
28 while( true )
29 {
30 // fire the next broadcast
31 evnt.broadcast();
32 // advance time
33 1::second => now;
34 }