Libraryless. Click here for Pure Java version (9886L/54K).
1 | static FixedRateTimer doEvery_stopOnException(double initialSeconds default delaySeconds, double delaySeconds, Runnable r, Runnable onStop default null) {
|
2 | if (r == null) null; |
3 | |
4 | FixedRateTimer timer = new(shorten(programID() + ": " + r, 80)); |
5 | Runnable r2 = r {
|
6 | try { r.run(); } catch print e {
|
7 | print("Cancelling timer due to error.");
|
8 | timer.cancel(); |
9 | pcallF(onStop); |
10 | } |
11 | }; |
12 | timer.scheduleAtFixedRate( |
13 | smartTimerTask(r2, timer, toMS_int(delaySeconds)), |
14 | toMS_int(initialSeconds), toMS_int(delaySeconds)); |
15 | ret timer; |
16 | } |
Began life as a copy of #1004683
download show line numbers debug dex old transpilations
Travelled to 3 computer(s): bhatertpkbcr, mowyntqkapby, mqqgnosmbjvj
No comments. add comment
| Snippet ID: | #1032668 |
| Snippet name: | doEvery_stopOnException - install a java.util.Timer, stop it when executed code throws an exception |
| Eternal ID of this version: | #1032668/5 |
| Text MD5: | 736186ecb0bddff4ecdae0c9cfb2e0b4 |
| Transpilation MD5: | f673c9470abc9cf2b6db0049afbe51ed |
| Author: | stefan |
| Category: | javax |
| Type: | JavaX fragment (include) |
| Public (visible to everyone): | Yes |
| Archived (hidden from active list): | No |
| Created/modified: | 2022-11-20 17:37:43 |
| Source code size: | 575 bytes / 16 lines |
| Pitched / IR pitched: | No / No |
| Views / Downloads: | 417 / 545 |
| Version history: | 4 change(s) |
| Referenced in: | [show references] |