Fork me on GitHub
#clr
<
2023-01-01
>
dangercoder22:01:08

Does anyone know how I can interop with async await in clojure-clr? https://learn.microsoft.com/en-us/dotnet/csharp/programming-guide/concepts/async/

dangercoder22:01:21

async/await interoperability blocks me from writing web apps using the newer versions of the .NET framework

dmiller02:01:02

Directly using async/await in ClojureCLR code is not a thing. My understanding is that async/await is implemented by C# compiler magic. It can be very instructive to decompile code that came from such constructs. And there are some good blog posts out there about it. All that means is that you can't directly use the style of async/await in ClojureCLR, but you can still interact with the constructs. All the async/await stuff just translates down into usage of the Task library. That can definitely be interacted with from ClojureCLR. I don't have any great examples for you, unfortunately. I'd be happy to help work it with you and/or others. ClojureCLR does have something very close to async/await. That comes in core.async, which has recently been ported. It plays its own set of compiler tricks, in the form of macro definitions. Those macros play similar games -- they walk the code of a function using the core.async constructs and rewrite. core.async is based on the model used in the Go language, with channels and buffers and other goodies. The relevant part here is the go construct. In fact, the announcement for core.async (https://clojure.org/news/2013/06/28/clojure-clore-async-channels) says this: > go is a macro that takes its body and examines it for any channel operations. It will turn the body into a state machine. Upon reaching any blocking operation, the state machine will be 'parked' and the actual thread of control will be released. This approach is similar to that used in http://msdn.microsoft.com/en-us/library/vstudio/hh191443.aspx. What would be an interesting project would be to build on the code rewriting capability of core.async and actually build the async/await constructs in ClojureCLR. Any takers? (I'm happy to help on the implementation, having finished the port on core.async.)

👍 6
2
dangercoder14:01:26

@U45FQSBF1 one small issue I have right now is that I'm using .NET 6 on Ubuntu and clojure-clr core async is compiled with .NET Framework 2.1, which means I can't use core.async? 😕