3 summary::Block the execution of a thread
8 Create a new instance, set the strong::test:: variable.
13 Answer whether the condition will block or not (boolean).
16 Wait until the condition is true and signalled. This only works in a Routine. This method yields a symbol (\hang), so that the clock doesn't reschedule the Routine.
18 c = Condition(false); fork { 0.5.wait; "started ...".postln; c.wait; "... and finished.".postln };
24 Wait for strong::value:: time, regardless of test. This only works in a Routine. This method yields a symbol (\hang), so that the clock doesn't reschedule the Routine.
26 c = Condition.new; fork { 0.5.wait; "started ...".postln; c.hang; "... and finished.".postln };
31 If link::#-test:: is true, reschedule blocked threads.
40 c = Condition.new(false);
44 "waited for 1 second".postln;
46 "waited for another second, now waiting for you ... ".postln;
48 "the condition has stopped waiting.".postln;
50 "waited for another second".postln;
51 "waiting for you ... ".postln;
54 "the condition has stopped waiting.".postln;
66 // a typical use is a routine that can pause under certin conditions:
69 fork { loop { 1.wait; "going".postln; c.wait } };
71 c.test = true; c.signal;
76 // the same, using hang
83 "waited for 1 second".postln;
85 "waited for another second, now waiting for you ... ".postln;
87 "the condition has stopped waiting.".postln;
89 "waited for another second".postln;
90 "waiting for you ... ".postln;
92 "the condition has stopped waiting.".postln;
100 Waiting for Synths to end (waitForFree) uses a Condition implicitly:
104 var mod = LFNoise2.kr(ExpRand(0.5, 2)) * 0.5;
105 var snd = mod * Blip.ar(Rand(200, 800) * (mod + 1));
107 FreeSelf.kr(mod < 0); // free the synth when amplitude goes below 0.
114 "started a synth".postln;
115 Synth(\help).waitForFree;
116 "This one ended. Wait a second, I will start the next one.".postln;
119 "This is it.".postln;