1 | static class QWithObjects<A> implements AutoCloseable { |
2 | S name = "Unnamed Queue"; |
3 | L<A> q = synchroLinkedList(); |
4 | ReliableSingleThread rst = new(r { _run() }); |
5 | volatile bool retired; |
6 | O performJob; |
7 | |
8 | *() {} |
9 | *(S *name) {} |
10 | |
11 | void add(Runnable r) { |
12 | q.add(r); |
13 | _trigger(); |
14 | } |
15 | |
16 | void _trigger() { |
17 | rst.name = name; |
18 | rst.go(); |
19 | } |
20 | |
21 | void add(O r) { |
22 | add(toRunnable(r)); |
23 | } |
24 | |
25 | void _run() { |
26 | Runnable r; |
27 | while (licensed() && !retired && (r = syncPopFirst(q)) != null) { |
28 | pcall { r.run(); } |
29 | } |
30 | } |
31 | |
32 | public void close() { retired = true; } // TODO: interrupt thread |
33 | void done() {} // legacy function |
34 | |
35 | bool isEmpty() { ret q.isEmpty(); } |
36 | int size() { ret q.size(); } |
37 | } |
Began life as a copy of #1000934
download show line numbers debug dex old transpilations
Travelled to 6 computer(s): bhatertpkbcr, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tvejysmllsmz, vouqrxazstgt
No comments. add comment
Snippet ID: | #1024003 |
Snippet name: | QWithObjects (runnable queue with arbitrary job objects, dev.) |
Eternal ID of this version: | #1024003/1 |
Text MD5: | 7bc81519593658c276ea142e9ea5449f |
Author: | stefan |
Category: | javax |
Type: | JavaX fragment (include) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2019-07-15 15:40:52 |
Source code size: | 762 bytes / 37 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 211 / 220 |
Referenced in: | [show references] |