Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

23
LINES

< > BotCompany Repo | #1023118 // dm_timerWithFieldSecondsInterval_startNow - interval is set in field and can be changed at runtime

JavaX fragment (include)

1  
static AutoCloseable dm_timerWithFieldSecondsInterval_startNow(S field, Runnable r) {
2  
  class DaTimer implements Runnable {
3  
    new Flag cancel;
4  
    DynModule m = dm_current_mandatory();
5  
    Long lastFired = null;
6  
    
7  
    run {
8  
      while (licensed() && !cancel.isUp()) {
9  
        if (lastFired != null) {
10  
          long interval = toMS(toDouble(get(m, field)));
11  
          if (interval <= 0) fail("Need delay > 0: " + field + " in " + m);
12  
          sleepUntilSysTime(lastFired+interval);
13  
        }
14  
        lastFired = sysNow();
15  
        if (licensed() && !cancel.isUp())
16  
          callF(r);
17  
      }
18  
    }
19  
  }
20  
  new DaTimer t;
21  
  startThread(t);
22  
  ret dm_ownResource(flagAsAutoCloseable(t.cancel));
23  
}

download  show line numbers  debug dex  old transpilations   

Travelled to 7 computer(s): bhatertpkbcr, cfunsshuasjs, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #1023118
Snippet name: dm_timerWithFieldSecondsInterval_startNow - interval is set in field and can be changed at runtime
Eternal ID of this version: #1023118/4
Text MD5: 75674a1193a93e86c92769428b132632
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2019-05-11 14:10:47
Source code size: 720 bytes / 23 lines
Pitched / IR pitched: No / No
Views / Downloads: 263 / 305
Version history: 3 change(s)
Referenced in: [show references]