Errata for Kotlin Coroutines by Tutorials 2nd Edition

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! :]

1 Like

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 :slight_smile:

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!

1 Like

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.
image

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! :]