In this video, learn how to start a coroutine by getting access to the Job value that’s returned from the launch method. Also, see the use of two coroutines in the same function and how they run in parallel.
- [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 process requests in parallel.…Now this will certainly come in handy…
- What Kotlin has to offer
- Working with lambdas
- Common Android extension functions
- Kotlin Android Extensions overview
- Making use of the Anko library
- Working with coroutines
- Nullability and collections
Skill Level Intermediate
Android App Development: Data Persistence Librarieswith Annyce Davis3h 59m Intermediate
Developing AWS Lambda Functions with Kotlinwith Troy Miles1h 55m Intermediate
1. Kotlin Overview
2. Extension Functions and Properties
3. Incorporating Anko
4. Advanced Anko
5. Working with Collections
- Mark as unwatched
- Mark all as unwatched
Are you sure you want to mark all the videos in this course as unwatched?
This will not affect your course history, your reports, or your certificates of completion for this course.Cancel
Take notes with your new membership!
Type in the entry box, then click Enter to save your note.
1:30Press on any video thumbnail to jump immediately to the timecode shown.
Notes are saved with you account but can also be exported as plain text, MS Word, PDF, Google Doc, or Evernote.