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

30
LINES

< > BotCompany Repo | #1017607 // class Q2 (now promoted to "Q", runnable queue that drops the thread when not needed)

JavaX fragment (include)

1  
static class Q2 implements AutoCloseable {
2  
  S name = "Unnamed Queue";
3  
  L<Runnable> q = synchroLinkedList();
4  
  ReliableSingleThread rst = new(r { _run() });
5  
  volatile bool retired;
6  
  
7  
  *() {}
8  
  *(S *name) {}
9  
  
10  
  void add(Runnable r) {
11  
    q.add(r);
12  
    rst.go();
13  
  }
14  
  
15  
  void add(O r) {
16  
    add(toRunnable(r));
17  
  }
18  
  
19  
  void _run() {
20  
    L<Runnable> l = cloneAndClearList(q);
21  
    for (Runnable r : l) {
22  
      if (!licensed() || retired) ret;
23  
      pcall { r.run(); }
24  
    }
25  
  }
26  
  
27  
  public void close() { retired = true; } // TODO: interrupt thread
28  
  
29  
  bool isEmpty() { ret q.isEmpty(); }
30  
}

Author comment

Began life as a copy of #1000934

download  show line numbers  debug dex  old transpilations   

Travelled to 14 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, irmadwmeruwu, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #1017607
Snippet name: class Q2 (now promoted to "Q", runnable queue that drops the thread when not needed)
Eternal ID of this version: #1017607/6
Text MD5: f6faf94f30a189f3a379775a7b5193d1
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2018-07-29 18:46:28
Source code size: 624 bytes / 30 lines
Pitched / IR pitched: No / No
Views / Downloads: 351 / 899
Version history: 5 change(s)
Referenced in: [show references]