3 summary::schedules functions to be evaluated in the future
6 A Scheduler can be used to schedule and reschedule functions to be evaluated at a specific time-point. The Scheduler's time needs to be advanced manually. In most cases you will probably want to use a Clock (e.g. link::Classes/TempoClock::, link::Classes/SystemClock::, link::Classes/AppClock::) instead, in which the march of time is handled for you.
12 A clock, like SystemClock.
14 If code::true::, link::#-sched:: will schedule tasks relative to the current absolute time ( link::Classes/Process#*elapsedTime#Main.elapsedTime:: ), otherwise to the current logical time of the scheduler ( link::#-seconds:: ).
16 Sets link::#-recursive::.
21 Schedules the task immediately. Equivalent to code::sched(0, task)::.
24 Schedule the task at code::delta:: seconds relative to the current time, as defined by the code::drift:: argument of the link::#*new#constructor::.
26 Regardless of what time a task is scheduled, it will only be awaken the next time link::#-seconds:: is set.
29 Schedule the task at absolute code::time:: in seconds.
32 Advance the current logical time by code::delta:: seconds. Has same effect as setting link::#-seconds::.
35 The current logical time of the scheduler.
37 Setting a new time will wake up (evaluate) any tasks scheduled within that time; a task that returns a new time will be rescheduled accordingly.
40 Returns whether the scheduling queue is empty.
43 Clears the scheduling queue
46 returns:: The instance of link::Classes/PriorityQueue:: used internally as scheduling queue.
49 If waking up items results in new items being scheduled, but some of them are already expired (scheduled at current time or earlier), this variable determines whether those items will be awaken as well in the same call to -seconds.
54 a = Scheduler(SystemClock);
56 a.sched(3, { "now it is 3 seconds.".postln; nil });
57 a.sched(5, { "now it is 5 seconds.".postln; nil });
58 a.sched(1, { "now it is 1 second.".postln; nil });
65 // the beats, seconds and clock are passed into the task function:
66 a.sched(1, { arg beats, secs, clock; [beats, secs, clock].postln });
69 // the scheduling is relative to "now":
70 a.sched(3, { "now it was 3 seconds.".postln });
71 a.sched(5, { "now it was 5 seconds.".postln });
72 a.sched(1, { "now it was 1 second.".postln });
79 // play a Routine or a task:
80 a.play(Routine { 5.do { arg i; i.postln; 1.yield } });
87 x = Scheduler(TempoClock.default);
91 ("next " ++ i ++ " in task." + Main.elapsedTime).postln;
104 loop { x.advance(0.1); 0.1.wait };
118 Pbind(\degree, Pseries(0, 2, 8), \dur, 0.25).play(x);