Hey guys I’m looking for a place to learn about Co...
# server
i
Hey guys I’m looking for a place to learn about Coroutines, but I search a place when I can learn about them deeply and in details. Knowing that I came from Java world and I’m comfortable with Threads and java.concurrency stuffs Could someone please recommend anything ?!
v
Coroutines are more like the newly coming lightweight user threads in Java
I didn't read it yet, but Baeldung often has nice articles: https://www.baeldung.com/kotlin/java-kotlin-lightweight-concurrency
👍 1
i
Thanks a lot Björn
p
j
Hmm. Coroutines are sort of the opposite of loom virtual threads though. One model is about asynchronous all the things, the other model is about continuations, so the programmer experience doesn't change.
v
I don't get what you mean, mind elaborating @James Richardson? With coroutines you make a call to a suspending function, the execution of the code at that spot suspends until the method is finished and then the next line is done, and all without blocking a platform thread. Same for Java virtual threads, no?
There are other explanations too, but essentially - async requires that you acknowledge the asynchronous stuff everywhere, loom sucks all that stuff up and so, for the programmer, it appears that everything is blocking again, which makes for a far simpler mental/programming model. Ultimately, of course its about an abstraction, but in this case its one that mostly you can't see...
v
Could be the time on the clock, but that was a pretty long article, and it had pretty much nothing about the question. 😕 And also your last comment does not really answer the question. You initially said they are different. I said they are same, aren't they? And you didn't really say anything about the question.
s
This may be the obvious suggestion, but our guides introduce coroutines essentially “from first principles”, so have a look at those as well if you haven’t yet! https://kotlinlang.org/docs/coroutines-guide.html
j
coroutines and virtual threads are not the same, and in some sense they are the opposite of each other. In one case (async/coroutines) the programmer needs to acknowledge which things may wait for IO and build that in to the programming model. (e.g. coloured functions etc). Virtual threads hide all the complexity by using continuations at the JVM level, so the programmer doesn't have to worry about it, and can just write boring old blocking style code. But that boring code will perform just as well as the complex async code, but be far easier to debug and reason about. It will probably have meaningful stacktraces! Coroutines are still a thing (they have been a thing for many decades already) and will still be useful for lots of reasons and particularly for some platforms and use cases, so they won't go away. https://blog.rockthejvm.com/ultimate-guide-to-java-virtual-threads/
👍 1
i
Thank u @Sebastian Aigner I’m following that guide right now, the thing is there is no “behind the scenes” explanation Some people (like me) really want to know how does it work behind, the hidden part. Especially for something cool and doing a lot of stuff easily, like Coroutines.
s
@Ismaïl I’d say this talk from Roman, who leads the coroutines effort, is still very relevant, and might give you exactly that deep-dive look that you were hoping for:

https://youtu.be/YrrUCSi72E8

. It’s from 2017, so it might not tackle topics like Structured Concurrency yet, but you might still learn a lot of the mechanics „under the hood“ from it!
i
Thanks a lot @Sebastian Aigner !
b
Hi @Ismaïl, I wrote a blog not to long ago which explains what happens during CPS transformations. The examples are a bit simplified, but might be a nice starting point nonetheless. https://blog.fresh-minds.nl/kotlin-coroutine-fundamentals-b9dbb68836d4 What also helped me was reading through this design document/proposal: https://github.com/Kotlin/KEEP/blob/master/proposals/coroutines.md
i
Thanks @Bas de Groot ! And thank u all guys, I guess I’m not going to ask for more resources any soon But feel free to share more if u find some 😁
m
Although I'm pretty late, I'd like to recomment this blog series that I learned a lot from 😄
❤️ 1
i
Thanks @Minsoo Cheong !