October 2021
Intermediate to advanced
500 pages
16h 23m
English
A coroutine builder is a function that creates a new coroutine. Most coroutine builders also start the coroutine immediately after creating it. Several builders are defined for you in the Coroutines library. The most commonly used coroutine builder is launch, a function defined as an extension to a class called CoroutineScope. You will see more information on scopes shortly; for now, you will use the subclass GlobalScope.
Launch a new coroutine by wrapping your call to fetchFlight in a call to the launch function defined on GlobalScope.
Listing 20.4 Launching a coroutine (FlightFetcher.kt)
private const val BASE_URL = "http://kotlin-book.bignerdranch.com/2e" private const val FLIGHT_ENDPOINT = "$BASE_URL/flight" ...
Read now
Unlock full access