From: Fredrik Tolf Date: Mon, 14 Feb 2022 16:47:57 +0000 (+0100) Subject: Actually implement event-driver timeouts. X-Git-Url: http://dolda2000.com/gitweb/?p=jagi.git;a=commitdiff_plain;h=2a11bb221932c2e5103e6df1ed2378247e569003 Actually implement event-driver timeouts. --- diff --git a/src/jagi/event/Driver.java b/src/jagi/event/Driver.java index 84238d2..a8475b4 100644 --- a/src/jagi/event/Driver.java +++ b/src/jagi/event/Driver.java @@ -59,6 +59,8 @@ public class Driver { } void handle(Watcher w, int evs) { + if(!watching.containsKey(w)) + return; try { pause(w); submit(() -> { @@ -88,8 +90,8 @@ public class Driver { boolean quit = false; Throwable error = null; try { + double now = time(); while(true) { - double now = time(); long timeout = 0; synchronized(selectors) { Double first = timeheap.keypeek(); @@ -109,6 +111,13 @@ public class Driver { } for(SelectionKey key : poll.selectedKeys()) handle((Watcher)key.attachment(), key.readyOps()); + now = time(); + while(true) { + Double first = timeheap.keypeek(); + if((first == null) || (first > now)) + break; + handle(timeheap.remove(), 0); + } } } catch(Throwable t) { error = t;