class library: Volume - remove debug message
[supercollider.git] / SCClassLibrary / Common / Core / Condition.sc
blobd511f378eaa77269925ed0c5c137f5a86d99a4a9
1 Condition {
2         var <>test, waitingThreads;
4         *new { arg test=false;
5                 ^super.newCopyArgs(test, Array(8))
6         }
7         wait {
8                 if (test.value.not, {
9                         waitingThreads = waitingThreads.add(thisThread.threadPlayer);
10                         \hang.yield;
11                 });
12         }
13         hang { arg value = \hang;
14                 // ignore the test, just wait
15                 waitingThreads = waitingThreads.add(thisThread.threadPlayer);
16                 value.yield;
17         }
19         signal {
20                 var tempWaitingThreads, time;
21                 if (test.value, {
22                         time = thisThread.seconds;
23                         tempWaitingThreads = waitingThreads;
24                         waitingThreads = nil;
25                         tempWaitingThreads.do({ arg thread;
26                                 thread.clock.sched(0, thread);
27                         });
28                 });
29         }
30         unhang {
31                 var tempWaitingThreads, time;
32                 // ignore the test, just resume all waiting threads
33                 time = thisThread.seconds;
34                 tempWaitingThreads = waitingThreads;
35                 waitingThreads = nil;
36                 tempWaitingThreads.do({ arg thread;
37                         thread.clock.sched(0, thread);
38                 });
39         }
42 FlowVar {
43         var value = \unbound;
44         var condition;
46         *new { arg inVal = \unbound;
47                 ^super.init(inVal)
48         }
49         init { arg inVal;
50                 value = inVal;
51                 condition = Condition { value != \unbound };
52         }
53         value_ { arg inVal;
54                 if (value ==  \unbound) {
55                         Error("cannot rebind a FlowVar").throw
56                 };
57                 value = inVal;
58                 condition.signal;
59         }
60         value {
61                 condition.wait
62                 ^value
63         }