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)

static AutoCloseable dm_timerWithFieldSecondsInterval_startNow(S field, Runnable r) {
  class DaTimer implements Runnable {
    new Flag cancel;
    DynModule m = dm_current_mandatory();
    Long lastFired = null;
    
    run {
      while (licensed() && !cancel.isUp()) {
        if (lastFired != null) {
          long interval = toMS(toDouble(get(m, field)));
          if (interval <= 0) fail("Need delay > 0: " + field + " in " + m);
          sleepUntilSysTime(lastFired+interval);
        }
        lastFired = sysNow();
        if (licensed() && !cancel.isUp())
          callF(r);
      }
    }
  }
  new DaTimer t;
  startThread(t);
  ret dm_ownResource(flagAsAutoCloseable(t.cancel));
}

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: 262 / 304
Version history: 3 change(s)
Referenced in: [show references]