Classes | Scheduling

Task : PauseStream : Stream : AbstractFunction : Object

a pauseable process
Source: Stream.sc


Task is a pauseable process. It is implemented by wrapping a PauseStream around a Routine. Most of its methods (start, stop, reset) are inherited from PauseStream.

Tasks are not 100% interchangeable with Routines.

Class Methods

Task.new(func, clock)



A Function to be evaluated.


A Clock in which to play the Routine. If you do not provide a Clock the default is an instance of TempoClock. Remember that methods which call Cocoa primitives (i.e. GUI functions) must be played in AppClock.

Inherited class methods

Instance Methods

.play(argClock, doReset: false, quant)

From superclass: PauseStream



(optional) Override the clock assigned in Task.new.


If true, the task will start over from the beginning. Default is false (task will resume where it was when it was last stopped).


See the Quant helpfile.

Other control methods

.start(argClock, quant)

From superclass: PauseStream

Restart the task from the beginning.

.resume(argClock, quant)

From superclass: PauseStream

Resume the task where it left off.


From superclass: PauseStream

Stop playing now.


From superclass: PauseStream

Stop playing now. (Pause and stop have the same implementation.)


From superclass: PauseStream

Set the stream to restart from the beginning the next time it's played.


Other objects might need to be aware of changes in the state of a task. The following notifications are broadcast to dependents registered with the Task object.

Inherited instance methods


What happens if you stop and start the task too quickly?

Based on the forked thread, you would expect the second "go" line of output to occur 0.2 seconds after the first, but in fact it happens two seconds later (the same amount of time the task waits between iterations). This is because the task must not schedule itself on the clock more than once. When the task is stopped, it remains scheduled until it wakes up again (based on its wait time). If, during this interval, the task were restarted, there would be two references to the task in the scheduler queue -- a situation that is irrecoverable short of stopping everything with command-period.

As a result, Task should be used for processes that need to start and stop relatively infrequently, but for which maximum stability is required. If you need fine-grained control over when and how the process stops and resumes (as is the case, for instance, with condition), Routine is preferred.