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
| // Task: | |
| // Implement polling with a timeout | |
| suspend fun makeNetworkRequest(): Result<String> { | |
| delay(100) | |
| return if (Random.nextBoolean()) { | |
| Result.success("hello") | |
| } else { | |
| Result.failure(RuntimeException("Bad luck")) | |
| } |
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
| // What it the output? | |
| import kotlinx.coroutines.* | |
| import kotlinx.coroutines.test.* | |
| import kotlinx.coroutines.ExperimentalCoroutinesApi | |
| @OptIn(ExperimentalCoroutinesApi::class) | |
| fun main() = runTest { | |
| launch(StandardTestDispatcher(testScheduler)) { | |
| println("Standard runs") |
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
| // 1. | |
| // Какой будет вывод? | |
| // Как сделать так, чтобы корутины выполнялись асинхронно и параллельно? | |
| fun main() = runBlocking { | |
| launch { | |
| Thread.sleep(3000) | |
| println(1) | |
| } | |
| launch { |
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
| // | |
| // Task 1 | |
| // What is the output? | |
| // | |
| import kotlinx.coroutines.* | |
| fun main() { | |
| runBlocking { | |
| val request = launch { |
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
| // What is the output of the function? | |
| fun main() { | |
| Habr() | |
| } | |
| class Habr { | |
| init { | |
| searchMagnit() |
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
| // | |
| // launch + try-catch | |
| // | |
| viewModelScope.launch { | |
| XXXXXXXXX { | |
| launch { | |
| try { | |
| throw RuntimeException("Bad luck") | |
| } catch (e: Exception) { |
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
| // Task: fix and refactor | |
| object Const { | |
| val INDEX = 1 | |
| } | |
| private var TAG = "ChatSessionController" | |
| open class ChatSessionController( | |
| private val accountRepository: ChatAccountRepository, |
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
| // You are fetching a user's Account Balance. | |
| // The network is flaky and frequently throws IOException. | |
| // You need to implement a robust retry mechanism. | |
| // | |
| // Create a utility function called retryWithBackoff and use it to call fetchBalance(). | |
| // | |
| // If the call fails, retry up to 3 times. | |
| // | |
| // The delay between retries should double each time. | |
| // 1st failure: Wait 1000ms |
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
| // Task | |
| // | |
| // Implement a function fetchTripSummary() using Kotlin Coroutines | |
| // that meets the following requirements: | |
| // | |
| // - Concurrent Execution: All three services must be called simultaneously to minimize loading time. | |
| // | |
| // - Selective Resilience: * If fetchWeather() throws an exception, the function should continue | |
| // and return the summary with a null weather field. | |
| // If fetchFlight() or fetchHotel() throws an exception, all other active fetches should be |
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
| // Task: will this code compile? | |
| fun <T> filterList(list: List<Any>, action: () -> Unit): List<T> { | |
| val resultList = mutableListOf<T>() | |
| for (element in list) { | |
| if (element is T) { | |
| resultList.add(element) | |
| } else { | |
| saveResult(action) | |
| } |
NewerOlder