sclass OnOffOscillator is AutoCloseable { double percentageOn = 50; Frequency frequency = freq(50); transient PingSource clientPingSource; transient Schedule schedule; transient Thread thread; transient new BoolVar on; *(PingSource *clientPingSource) {} void init { schedule = new Schedule; schedule.add(0, r { clientPingSource?.action(null); on.set(); }); schedule.add(percentageOn/100, r { on.unset(); clientPingSource?.action(-> { temp tempPingPrivileged(); on.waitUntilTrue(); true; }); }); schedule.jumpFromTo(1, 0); schedule.speedUp(frequency!); } void start { init(); thread = startThread("OnOffOscillator", r { schedule.run(); }); } // Note: May leave switch in on or off state public void stop aka close() { interruptThread(thread); thread = null; } }