Pretty cool use case for virtual threads. Recently I implemented something with core.async in order to batch messages and dispatch them to some UI code at a fixed rate. It was definitely a lot more complicated than using a single sempahore like shown in this article.<p>On a related note, it would be nice to have an implementation of CSP using proper virtual threads rather than the thread pool currently used by core.async. The promesa library currently has a proof-of-concept[1], but it doesn't seem interoperable with existing core.async code.<p>[1] <a href="https://funcool.github.io/promesa/latest/promesa.exec.csp.html" rel="nofollow">https://funcool.github.io/promesa/latest/promesa.exec.csp.ht...</a>
One related article that I found interesting: <a href="https://ericnormand.me/guide/clojure-virtual-threads" rel="nofollow">https://ericnormand.me/guide/clojure-virtual-threads</a>
Good to know that refs and atoms are not safe to use in virtual threads. I would have definitely found that out the hard way since atoms are so simple to use.
> things get complicated with virtual threads, they shouldn't be pooled, as they aren't a scarce resource<p>Why not pool virtual threads, though? I get that they’re not scarce, but if you’re looking to limit throughput anyway wouldn’t that be easier to achieve using a thread pool than semaphores?