Skip to content

Instantly share code, notes, and snippets.

@af2905
Last active May 13, 2024 08:41
Show Gist options
  • Save af2905/d823b11ca73e2ca79cb082608cc3f7b2 to your computer and use it in GitHub Desktop.
Save af2905/d823b11ca73e2ca79cb082608cc3f7b2 to your computer and use it in GitHub Desktop.
tricky questions_full_code
class MainActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContent {
CoroutinestrickyquestionsTheme {
Surface(
modifier = Modifier.fillMaxSize(),
color = MaterialTheme.colorScheme.background
) {
Box(modifier = Modifier.wrapContentSize()) {
Button(
onClick = {
startCoroutine()
}
) {
Text(text = "Start coroutine")
}
}
}
}
}
}
private fun startCoroutine() {
val myScope: CoroutineScope = CoroutineScope(context = Job())
myScope.launch {
delay(500L)
println("A")
coroutineScope {
launch {
delay(1000L)
println("B")
}
delay(100L)
println("C")
}
println("D")
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment