From the course: Intermediate Kotlin for Android Developers

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Anko coroutines: Launch advanced

Anko coroutines: Launch advanced

From the course: Intermediate Kotlin for Android Developers

Start my 1-month free trial

Anko coroutines: Launch advanced

- [Instructor] We can easily start a coroutine that doesn't block the main thread. But what about another coroutine? Do they block each other from getting work done? Well, no, they don't have to. Let's implement this startWithLaunchMultiple method. We're first going to duplicate the code that we have here inside of the previous test. And let's paste it, and starting on line 38, and then we're just going to copy the code for our launch coroutine. And we're going to duplicate that right underneath, and then let's change what gets printed. The first one, on line 42, we're going to change it to Inside1, and then here, on line 47, we're going to change it to Inside2. Now let's go ahead and run this test. So if we look at our results, we get starting, and then inside 1, and inside 2. And then finally, stopping. This helps us to see that both coroutines were able to run successfully under that second and a half that we let our main thread sleep. This is because coroutines allow you to…

Contents