interrupt event loop on exceptions so that they are seen immediately

This commit is contained in:
akhil 2014-01-28 12:21:57 -08:00
parent 3a00095032
commit a9136f94d9
1 changed files with 12 additions and 3 deletions

View File

@ -67,6 +67,7 @@ public final class EventLoop {
private final BlockingQueue<Event> eventQueue = new LinkedBlockingQueue<>();
private final AtomicInteger hooks = new AtomicInteger(0);
private final AsyncHandle asyncHandle;
private final AsyncHandle interruptMainLoopHandle;
private final Thread mainThread;
private Callback isHandlerRegistered = null;
@ -382,7 +383,8 @@ public final class EventLoop {
} else {
pendingException.addSuppressed(ex);
}
stop();
// interrupt uvLoop.run() so that pending exception can be thrown synchronously
interruptMainLoopHandle.send();
}
}
},
@ -411,8 +413,8 @@ public final class EventLoop {
LibUV.chdir(workDir);
LOG = logger("eventloop");
asyncHandle = new AsyncHandle(uvLoop);
asyncHandle = new AsyncHandle(uvLoop);
asyncHandle.setAsyncCallback(new AsyncCallback() {
@Override
public void onSend(int status) throws Exception {
@ -423,9 +425,16 @@ public final class EventLoop {
}
}
});
asyncHandle.unref();
interruptMainLoopHandle = new AsyncHandle(uvLoop);
interruptMainLoopHandle.setAsyncCallback(new AsyncCallback() {
@Override
public void onSend(int status) throws Exception {
stop();
}
});
interruptMainLoopHandle.unref();
}
public String version() {