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

Anko coroutines: Async

From the course: Intermediate Kotlin for Android Developers

Start my 1-month free trial

Anko coroutines: Async

- [Instructor] The Async function is useful when you need to return a value from your coroutine. So we're going to implement the methods here in the coroutine's Async test class in order to try it out. We're going to first start by using the Async method the same way that we would use the launch method. So for that we're going to grab some code from the coroutine's launch class, so let's switch over there now. And we'll grab the code from this first test. Go back to our test here on line nine and paste that in. Let's accept all of our imports. And the only thing we're going to change is here on line 14. Instead of using the launch function we're going to use Async. So let's go ahead and run the test. So if we look at our results we're getting starting, inside and stopping. The same thing we had before just like when we were running launch, except for now we're taking advantage of the Async call. So now let's look at a better usage of the Async call. For that we're going to implement…

Contents