Created
June 27, 2022 17:37
-
-
Save aqua30/d04864afb116473a1fb73ebcdfe6b9b5 to your computer and use it in GitHub Desktop.
This file contains 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
private fun processTask(id: Int) { | |
viewModelScope.launch(Dispatchers.IO) { | |
try { | |
Log.e("Tag","thread = ${Thread.currentThread().name}") | |
backgroundTask(id) | |
} finally { | |
Log.e("Tag","cancelled $id") | |
} | |
} | |
} | |
private suspend fun backgroundTask(id: Int) { | |
val delay = id + Random.nextInt(5) | |
Log.e("Tag","delay for id $id is $delay") | |
delay(delay * 1000L) | |
_itemsState[id] = itemsState[id].copy( | |
taskStatus = TaskStatus.COMPLETED | |
) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment