From 2a11bb221932c2e5103e6df1ed2378247e569003 Mon Sep 17 00:00:00 2001 From: Fredrik Tolf Date: Mon, 14 Feb 2022 17:47:57 +0100 Subject: [PATCH] Actually implement event-driver timeouts. --- src/jagi/event/Driver.java | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) 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; -- 2.11.0