sclass MultiSleeper extends RestartableCountdown is ISleeper_v2 { new TreeMultiMap entries; void check { var time = nextWakeUpTime(); var action = firstValue(entries); setTargetTime(time == null ? 0 : time.sysTime(), r { L toCall; synchronized(MultiSleeper.this) { toCall = entries.get(time); entries.remove(time); } check(); pcallFAll(toCall); }); } // API synchronized Timestamp nextWakeUpTime() { ret firstKey(entries); } public synchronized Sleeping doLater(Timestamp targetTime, Runnable r) { if (r == null || targetTime == null) null; entries.put(targetTime, r); check(); } }