static class QWithObjects implements AutoCloseable {
S name = "Unnamed Queue";
L q = synchroLinkedList();
ReliableSingleThread rst = new(r { _run() });
volatile bool retired;
O performJob;
*() {}
*(S *name) {}
void add(Runnable r) {
q.add(r);
_trigger();
}
void _trigger() {
rst.name = name;
rst.go();
}
void add(O r) {
add(toRunnable(r));
}
void _run() {
Runnable r;
while (licensed() && !retired && (r = syncPopFirst(q)) != null) {
pcall { r.run(); }
}
}
public void close() { retired = true; } // TODO: interrupt thread
void done() {} // legacy function
bool isEmpty() { ret q.isEmpty(); }
int size() { ret q.size(); }
}