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.

1  
sclass DoLater implements AutoCloseable {
2  
  long targetSysTime;
3  
  volatile Runnable action;
4  
  transient settable ISleeper sleeper;
5  
  transient Executor executor;
6  
  transient new Flag enabled;
7  
  transient new Flag cancelledOrExecuted;
8  
  
9  
  *() {}
10  
  *(long *targetSysTime, Runnable *action) {}
11  
  
12  
  void enable() {
13  
    if (!enabled.raise()) ret;
14  
    if (sleeper == null) sleeper = defaultSleeper();
15  
    sleeper.doLater(targetSysTime, r {
16  
      if (!cancelledOrExecuted.raise()) ret;
17  
      runWithExecutor(action, executor);
18  
    });
19  
  }
20  
  
21  
  // returns true iff successful
22  
  bool cancel() {
23  
    if (!cancelledOrExecuted.raise()) false;
24  
    ret true with close();
25  
  }
26  
  
27  
  public void close {
28  
    cancelledOrExecuted.raise();
29  
    //dispose sleeper;
30  
  }
31  
}

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: 360 / 1133
Version history: 15 change(s)
Referenced in: [show references]