If anyone is interested, I think I found a possible solution.
First, I took Araq's suggestion of wrapping the actual implementation of
callbacks inside a regular procedure: normally, if an exception gets thrown, it
will not be propagated like the C example, however, as I said previously, if
the event loop is stopped, it will.
So, I've added `uv_stop` inside the `except` block, and it seems like it's
working as expected: unhandled exceptions makes the program exit, including the
ones that are thrown by other futures.
proc tcpConnectionOnConnectImpl(req: ptr uv_connect_t, status: cint) =
...
self.stream = stream
fut.complete(self)
proc tcpConnectionOnConnect(req: ptr uv_connect_t, status: cint) {.cdecl.} =
try:
tcpConnectionOnConnectImpl(req, status)
except:
uv_stop(defaultLoop.loop)
raise
Run