CopyPastor

Detecting plagiarism made easy.

Score: 1.980581582310688; Reported for: String similarity, Exact paragraph match Open both answers

Possible Plagiarism

Plagiarized on 2021-12-20
by Abdul Momen

Original Post

Original - Posted on 2019-12-27
by Tushar Saha



            
Present in both answers; Present only in the new answer; Present only in the old answer;


You can try some thing like this:
suspend fun saveInDb() { val value = GlobalScope.async { delay(1000) println("thread running on [${Thread.currentThread().name}]") 10 } println("value = ${value.await()} thread running on [${Thread.currentThread().name}]") }
await will wait for the coroutine to finish and then run code below it
fun onClick(view: View) { res = "" button.isEnabled = false GlobalScope.launch(Dispatchers.Main){ // launches coroutine in main thread updateUi() } } suspend fun updateUi(){ val value = GlobalScope.async { // creates worker thread res = withContext(Dispatchers.Default) { test() } } println(value.await()) //waits for workerthread to finish button.isEnabled = true //runs on ui thread as calling function is on Dispatchers.main }
You can try some thing like this:
suspend fun saveInDb() { val value = GlobalScope.async { delay(1000) println("thread running on [${Thread.currentThread().name}]") 10 } println("value = ${value.await()} thread running on [${Thread.currentThread().name}]") }
await will wait for the coroutine to finish and then run code below it
fun onClick(view: View) { res = "" button.isEnabled = false GlobalScope.launch(Dispatchers.Main){ // launches coroutine in main thread updateUi() } }
suspend fun updateUi(){ val value = GlobalScope.async { // creates worker thread res = withContext(Dispatchers.Default) { test() } } println(value.await()) //waits for workerthread to finish button.isEnabled = true //runs on ui thread as calling function is on Dispatchers.main }

        
Present in both answers; Present only in the new answer; Present only in the old answer;