Creating this topic to catch any typos and bugs in the 2nd Edition of Kotlin Coroutines by Tutorials.
Hi! The âBroadcastChannelOpenSubscriptionExampleâ example for chapter 12 doesnât appear to produce the expected output. The output given in the book is:
Press a key to exit...
Consumer 2: Grapes
Consumer 1: Grapes
Consumer 2: Strawberry
Consumer 1: Strawberry
but the actual output Iâm getting is just:
Press a key to exit...
Really enjoying the book so far though, thanks!
@nisrulz Can you please help with this when you get a chance? Thank you - much appreciated! :]
Chapter 4, Page 78 under the heading âHandling the continuationâ
This paragraph starts with, âIn the last version of getUser(), you used suspendCoroutine() from the Coroutines API.â
This is not true. The last version simply had us mark a function with the âsuspendâ keyword. The function at the time was called âgetUserSuspend()â
This paragraph is probably confusing the information given on page 75 where a hypothetical solution is offered for migrating to coroutines with functions that belong to an API for which we do not have control over. It was for a fictional function fun readFile(path:String, onReady: (File) -> Unit)
The paragraph on page 78 gets confusing because it goes on to explain the intricacies of suspendCoroutine() which we have not actually put to practice yet.
@filbabic Can you please help with this when you get a chance? Thank you - much appreciated! :]
Hey @chuck_taylor!
Thanks for pointing this out!
Youâre right, it gets a bit confusing because there are different functions involved, and the hypothetical solution is there to paint a picture of what you can do with coroutines & suspend functions.
We have this under the radar, and will change it up to make it more sensible, in the next edition of the book! :]
Hey @filbabic! Finally finding time to work through this book
Today was chapter one and I found two small typos:
- âwhere each operation has its own ambda parameter.â ambda â lambda
- âWith this, you are passing an implementation of the interface to the function that is executing the long-running task.â At this point you havenât shown this, but only the interface declaration.
Iâm excited to read more!
Hey @vgonda!
Thanks for taking the time to write this up! Iâm super excited to get your feedback on the book. :]
If thereâs anything youâd want us to fix/clean up, let me know and weâll plan it for the next edition (which I think should be soon).
Thanks! I hope you love the book!
Iâm still loving it!
Chapter 5 errata:
In WTGFH it mentions âSince this is the last chapter in the first sectionâ, however there are 4 more chapters in the section.
Finished the book. Great work and kudos to the authors. I learned a ton and have a great foundation on Coroutines.
For the next update if possible:
-
remove channels since I believe they are deprecated, I think flows are the new recommended approach
-
for Android devs like myself, remove Anko since it is also deprecated and spend some time if possible on using stateflow vs liveData. I know the API is constantly changing and moving fast but that was one topic that might help future devs reading the book.
-
for Android use new lifecycle methods to collect flows from the Android team: Safer way to collect flows
-
definitely an opinion but using MVVM vs MVP
Again, these are just suggestions. Much Appreciated!
Angel
Hi!
In Section 4: Creating your own suspendable API
I donât understand why the last snippet with executeBackground{} doesnât work. Theoretically getValue {} supposed to return the value for us, but instead it returns a kotlin.Unit type. Why is this the case and what is the remedy to return from a lambda?
I tried numerous ways I couldnât get the type (User) back in this case.
Hey @kristof1992!
Unfortunately, what youâre trying to do here doesnât make much sense from a lifecycle/function execution standpoint.
Youâre calling getValue
which provides a block of code to get a value in.
Within the block, you call a function that exposes a callback where the value returned/processed is available. As such, this function returns Unit
and not the value you need.
In the chapter, weâre using getUserFromNetwork
or getUserSuspend
to return a value without a callback and in this sense, the function has a return type.
Hope this make sense! :]