This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
requestScope.async { | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
val value : Deferred<Int> = requestScope.async { | |
42 | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
requestScope.launch { | |
val moviesComedy = loadMovies("Comedy") | |
val moviesAction = loadMovies("Action") | |
launch(Dispatchers.Main) { | |
showMoviesGenre(moviesComedy) | |
showMoviesGenre(moviesAction) | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
requestScope.launch(Dispatchers.Main) { | |
val moviesComedy = withContext(Dispatchers.IO) { loadMovies("Comedy") } | |
val moviesAction = withContext(Dispatchers.IO) { loadMovies("Action") } | |
showMoviesGenre(moviesComedy) | |
showMoviesGenre(moviesAction) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
requestScope.launch(Dispatchers.Main) { | |
val moviesComedy = async(Dispatchers.IO) { loadMovies("Comedy") }.await() | |
val moviesAction = async(Dispatchers.IO) { loadMovies("Action") }.await() | |
showMoviesGenre(moviesComedy) | |
showMoviesGenre(moviesAction) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
requestScope.launch(Dispatchers.Main) { | |
val moviesComedy = async(Dispatchers.IO) { loadMovies("Comedy") } | |
val moviesAction = async(Dispatchers.IO) { loadMovies("Action") } | |
showMoviesGenres(listOf(moviesComedy.await(), moviesAction.await()) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
suspend fun loadMovies() { | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
interface Continuation<in T> { | |
val context: CoroutineContext | |
fun resume(value: T) | |
fun resumeWithException(exception: Throwable) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fun <T> Continuation<T>.resume(value: T) | |
fun <T> Continuation<T>.resumeWithException(exception: Throwable) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
suspend fun makeLogin(login: String, password: String): Token { | |
// make request | |
return Token("akjsdhakjhdkshdakdjhkashdkaj") | |
} | |
suspend fun loadMovies(token: Token): List<Movie> { | |
// make request with token | |
return listOf(Movie("Avengers 1"), Movie("Duna")) | |
} |