4 ms·
Nim's `multisync` macro is another cool approach to this. It allows the function to be called isomorphically regardless of synchronicity, determining the latter
by pickdenis 8y ago
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/sidechannel.nim#L17 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.
- dom96 8y agoNice to see that others are finding this useful. :)