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

31
LINES

< > BotCompany Repo | #1025189 // DoLater

JavaX fragment (include) [tags: use-pretranspiled]

Transpiled version (10378L) is out of date.

sclass DoLater implements AutoCloseable {
  long targetSysTime;
  volatile Runnable action;
  transient settable ISleeper sleeper;
  transient Executor executor;
  transient new Flag enabled;
  transient new Flag cancelledOrExecuted;
  
  *() {}
  *(long *targetSysTime, Runnable *action) {}
  
  void enable() {
    if (!enabled.raise()) ret;
    if (sleeper == null) sleeper = defaultSleeper();
    sleeper.doLater(targetSysTime, r {
      if (!cancelledOrExecuted.raise()) ret;
      runWithExecutor(action, executor);
    });
  }
  
  // returns true iff successful
  bool cancel() {
    if (!cancelledOrExecuted.raise()) false;
    ret true with close();
  }
  
  public void close {
    cancelledOrExecuted.raise();
    //dispose sleeper;
  }
}

download  show line numbers  debug dex  old transpilations   

Travelled to 8 computer(s): bhatertpkbcr, ekrmjmnbrukm, mqqgnosmbjvj, onxytkatvevr, pyentgdyhuwx, pzhvpgtvlbxg, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #1025189
Snippet name: DoLater
Eternal ID of this version: #1025189/16
Text MD5: 033e0b6aa750d85b151edb316aa365dc
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2023-03-22 14:26:49
Source code size: 780 bytes / 31 lines
Pitched / IR pitched: No / No
Views / Downloads: 359 / 1131
Version history: 15 change(s)
Referenced in: [show references]