Libraryless. Click here for Pure Java version (8743L/51K).
sclass OnOffOscillator is AutoCloseable { double percentageOn = 50; Frequency frequency = freq(50); transient PingSource clientPingSource; transient Schedule<Runnable> schedule; transient Thread thread; transient new BoolVar on; *(PingSource *clientPingSource) {} void init { schedule = new Schedule<Runnable>; 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; } }
download show line numbers debug dex old transpilations
Travelled to 3 computer(s): bhatertpkbcr, ekrmjmnbrukm, mqqgnosmbjvj
No comments. add comment
Snippet ID: | #1033552 |
Snippet name: | OnOffOscillator |
Eternal ID of this version: | #1033552/5 |
Text MD5: | 99dc6817c6adeb56ecc85a99b44a78d7 |
Transpilation MD5: | 948eeffe16c5dbe398ca810c5e1f524e |
Author: | stefan |
Category: | javax / execution |
Type: | JavaX fragment (include) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2021-11-03 14:44:48 |
Source code size: | 960 bytes / 40 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 170 / 280 |
Version history: | 4 change(s) |
Referenced in: | #1034167 - Standard Classes + Interfaces (LIVE, continuation of #1003674) |