Nim's `multisync` macro is another cool approach to this. It allows the function to be called isomorphically regardless of synchronicity, determining the latter using the type system. In the following example, the `writeResponse` proc can be called from either a synchronous environment on a `Stream` or from an asynchronous environment using `AsyncStream`.
https://github.com/sid-code/nmoo/blob/master/src/nmoo/sidech...
There is a bit of glue code holding this together, but I find it really neat. There's no event loop hack, just static polymorphism.