Answers for "kotlin coroutine builders"

2

kotlin coroutines

import kotlinx.coroutines.*
// Asynchronous execution
fun main() {
  GlobalScope.launch { 	// creates a new coroutine and continues
    doWorld()			// suspending function
  }
  println("World !") 	// execution continues even while coroutine waits
  runBlocking { 		// block main thread for 4 s (waits for 1rst coroutine)
  	delay(4000L) 		
  }
}
suspend fun doWorld() {
  delay(2000L) 		// non-blocking delay for 2000 milliseconds
  println("Hello")	// printed after "World !"
}
Posted by: Guest on April-21-2021
0

kotlin coroutines

// Kotlin coroutines
    def coroutines_version = "1.5.0"
    implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core: $coroutines_version"
Posted by: Guest on July-11-2021
1

kotlin coroutine builders

launch - Launches new coroutine without blocking
current thread and returns a reference to the coroutine
as a Job.
runBlocking - Runs new coroutine and blocks current
thread interruptible until its completion.
async - Creates new coroutine and returns its future
result as an implementation of Deferred.
withContext - Change a coroutine context for some
block.
Posted by: Guest on January-15-2021

Browse Popular Code Answers by Language