2 summary:: A utility for background tasks that survive cmd-period
3 categories:: Scheduling, Libraries>JITLib>GUI
4 related:: Classes/CmdPeriod
7 SkipJack is a utility to run a function in the background repeatedly, that survive cmd-period.
9 A typical use is with a window displaying the state of some objects every now and then. (This is better in some cases than
10 updating the GUI at every change. If the changes happen fast, you don't choke your CPU on gui updating.)
12 But SkipJack is useful whenever you need a periodic function to run in the background and not go away if the user hits cmd-period.
21 A link::Classes/Function:: to repeat in the background.
24 The time interval at which to repeat. It can also be a stream or a function that returns a number.
27 A test whether to stop the task now. Usually a Function.
30 A name for this skipjack. Used for posting information and in the link::#*stop:: classmethod.
33 The clock that plays the task. Default is link::Classes/AppClock::, so SkipJack can call GUI primitives. If you need more precise timing, you can supply your own clock, and use defer only where necessary.
36 When true (default) SkipJack starts automatically as it is created.
39 Stop a skipjack by name.
45 The default clock (AppClock)
48 When true, SkipJack posts messages when it starts, stops or restarts.
51 The global set of all skipjacks.
57 Get or set the time interval.
60 The internal Routine that wraps updateFunc.
63 The name of this skipjack.
66 The current stopTest. (see argument in link::#*new:: )
78 Get or set the clock used. This will only be updated when the skipjack restarts.
81 The updateFunc set by the argument to link::#*new::
86 w = SkipJack({ "watch...".postln; }, 0.5, name: "test");
87 SkipJack.verbose = true; // post stop/wakeup logs
92 // now try to stop with cmd-. : SkipJack always restarts itself.
101 w = SkipJack({ "watch...".postln; }, 0.5, { a == 10 }, "test");
102 a = 10; // fulfil stopTest
105 Typical use: SkipJack updates a window displaying the state of some objects every now and then.
109 d.win = Window("dict", Rect(0,0,200,60)).front;
110 d.views = [\a, \b].collect { |name, i|
111 StaticText(d.win, Rect(i * 100,0,96,20))
112 .background_(Color.yellow).align_(0).string_(name);
116 [\a, \b].do { |name, i|
117 d.views[i].string_(name ++ ":" + d[name])
126 d.a = 123; // updates should be displayed
128 d.win.close; // when window closes, SkipJack stops.
131 If you need to get rid of an unreachable skipjack:
133 SkipJack({ "unreachable, unkillable...".postln }, name: "jack");
135 SkipJack.stopAll // do this to stop all;
137 SkipJack.stop("jack"); // reach it by name and stop