sclass MultiSleeper is ISleeper, AutoCloseable { MultiSetMap<Timestamp, Runnable> entries = treeMultiSetMap(); new RestartableCountdown countdown; private void check { var time = nextWakeUpTime(); var action = firstValue(entries); countdown.setTargetTime(time == null ? 0 : time.sysTime(), r { Set<Runnable> toCall; synchronized(MultiSleeper.this) { toCall = entries.get(time); entries.remove(time); check(); } pcallFAll(toCall); }); } private synchronized void removeEntry(Timestamp targetTime, Runnable action) { entries.remove(targetTime, action); } // API synchronized Timestamp nextWakeUpTime() { ret firstKey(entries); } public synchronized Sleeping doLater(Timestamp targetTime, Runnable r) { if (r == null || targetTime == null) null; targetTime = max(targetTime, tsNow()); entries.put(targetTime, r); check(); ret new Sleeping(targetTime, r) { close { removeEntry(targetTime, r); } }; } close { dispose countdown; } }
Began life as a copy of #1033563
download show line numbers debug dex old transpilations
Travelled to 2 computer(s): mqqgnosmbjvj, wnsclhtenguj
No comments. add comment
Snippet ID: | #1036585 |
Snippet name: | MultiSleeper backup 2 |
Eternal ID of this version: | #1036585/1 |
Text MD5: | d66bad59222765209dc6d307d14b8006 |
Author: | stefan |
Category: | javax / timers |
Type: | JavaX fragment (include) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2023-03-22 15:04:21 |
Source code size: | 1133 bytes / 44 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 130 / 144 |
Referenced in: | [show references] |