From the course: Intermediate Kotlin for Android Developers
Unlock the full course today
Join today to access over 22,500 courses taught by industry experts or purchase this course individually.
Anko coroutines: Suspending functions
From the course: Intermediate Kotlin for Android Developers
Anko coroutines: Suspending functions
- [Instructor] Let's take a look at suspending functions and how we can take advantage of them. We're here inside of the CoroutinesAsync class and we're going to add a new function in order to test suspending functions. Let's go ahead and copy what we have here inside of our previous function, usingAsyncTwice, and we'll just paste it at the bottom of the class file, and let's rename this one to usingAsyncWithSuspendFunction. Then, instead of having two asynchronous coroutines nested inside, let's just pair this down to one. We'll delete what we have here in our second one, and let's go ahead and get rid of this summation and just change it to the result instead of the sum. Now, we're back to having just one inner coroutine. The next thing we want to do is extract out the code inside of our async lambda to a new function. Let's highlight the work that we have here inside of our async lambda from line 71 to 73, and we're just going to create a new function called ourWork. It's going to…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.