sclass OnOffOscillator is AutoCloseable { double percentageOn = 50; Frequency freq = freq(50); transient Schedule schedule; transient Thread thread; void init { schedule = new Schedule; schedule.add(0, r { myPingSource.action(null); on.set(); }); schedule.add(percentageOn/100, r { on.unset(); myPingSource.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; } }