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)

static class Q2 implements AutoCloseable {
  S name = "Unnamed Queue";
  L<Runnable> q = synchroLinkedList();
  ReliableSingleThread rst = new(r { _run() });
  volatile bool retired;
  
  *() {}
  *(S *name) {}
  
  void add(Runnable r) {
    q.add(r);
    rst.go();
  }
  
  void add(O r) {
    add(toRunnable(r));
  }
  
  void _run() {
    L<Runnable> l = cloneAndClearList(q);
    for (Runnable r : l) {
      if (!licensed() || retired) ret;
      pcall { r.run(); }
    }
  }
  
  public void close() { retired = true; } // TODO: interrupt thread
  
  bool isEmpty() { ret q.isEmpty(); }
}

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: 350 / 898
Version history: 5 change(s)
Referenced in: #1034167 - Standard Classes + Interfaces (LIVE, continuation of #1003674)