top | item 38291308

(no title)

peterisdirsa | 2 years ago

I don't get it. How is this different than using standard Java ExecutorService & co features?

discuss

order

Shawnecy|2 years ago

I'm curious as well. Once you can use an ExecutorService with virtual threads, the gap seems a bit thin.

The best I can tell is that coroutines are a bit lighter weight (in terms of what state is managed) and have a bit simpler usage out-of-the-box.

But I've not used them myself so maybe I'm not seeing how big of advantage those are or perhaps there's more to it than that?

jayd16|2 years ago

Well for one, virtual threads would be implicit blocking and this style is explicit.

mst|2 years ago

It explicitly says it's not for actual use.

The point (I think) was as an exercise to demonstrate it was possible to implement in 'userland' and how they did so.

tadfisher|2 years ago

The runtime uses ExecutorService and friends to run coroutines, which are bits of CPS-transformed Kotlin code that are generated when you compile a 'suspend fun' declaration.

lfmunoz4|2 years ago

The way the code looks is completely different and significantly cleaner and faster to write in Kotlin. Actual performance and final functionality is likely to be same.