todd.ginsberg
05/19/2023, 12:16 PMwakingrufus
05/19/2023, 2:08 PMamanda.hinchman-dominguez
06/08/2023, 10:34 PMamanda.hinchman-dominguez
06/08/2023, 10:35 PMamanda.hinchman-dominguez
06/08/2023, 10:35 PMwakingrufus
06/14/2023, 9:56 PMwakingrufus
06/14/2023, 10:54 PMLinda Zhou
07/21/2023, 2:54 AMwakingrufus
10/04/2023, 3:39 PMwakingrufus
08/05/2024, 6:23 PMDariusz Kuc
08/19/2024, 8:18 PMamanda.hinchman-dominguez
11/25/2024, 9:26 PMamanda.hinchman-dominguez
12/19/2024, 6:59 PMamanda.hinchman-dominguez
01/29/2025, 3:47 PMamanda.hinchman-dominguez
01/30/2025, 10:51 PMFabio Gottlicher
01/31/2025, 3:06 PMamanda.hinchman-dominguez
01/31/2025, 8:42 PMtask1.join()
appears to messing with the timing of the print. This makes sense post discussionamanda.hinchman-dominguez
01/31/2025, 8:42 PMfun log(message: String) {
println("$message | current thread: ${Thread.currentThread().name}")
}
//TIP To <b>Run</b> code, press <shortcut actionId="Run"/> or
// click the <icon src="AllIcons.Actions.Execute"/> icon in the gutter.
fun main() = runBlocking {
val job = launch {
log("job launched")
val task1 = launch {
log(" task1")
delay(1000)
log(" task1 complete ")
}
val task2: Deferred<String> = async {
log(" task2")
delay(1000)
//log(" task2 complete")
" task2 async"
}
task1.join() <---- forced join
val task3 = launch {
log(" task3")
delay(1000)
log(" task3 complete")
}
log(" task2 status: $task2")
log(task2.await())
log(" task2 status: $task2")
}
log("Start job")
job.join()
log("Program ends")
}
amanda.hinchman-dominguez
01/31/2025, 8:42 PMamanda.hinchman-dominguez
01/31/2025, 8:43 PMStart job | current thread: main
job launched | current thread: main
task1 | current thread: main
task2 | current thread: main
task1 complete | current thread: main
task2 status: DeferredCoroutine{Completed}@f5f2bb7 | current thread: main
task2 async | current thread: main
task2 status: DeferredCoroutine{Completed}@f5f2bb7 | current thread: main
task3 | current thread: main
task3 complete | current thread: main
Program ends | current thread: main
amanda.hinchman-dominguez
01/31/2025, 8:44 PMtask1.join()
, we now get the Active/Completed statusamanda.hinchman-dominguez
01/31/2025, 8:44 PMfun main() = runBlocking {
val job = launch {
val task1 = launch {
log(" task1")
delay(1000)
log(" task1 complete ")
}
val task2: Deferred<String> = async {
log(" task2")
delay(1000)
log(" task2 complete")
" task2 returned"
}
val task3 = launch {
log(" task3")
delay(1000)
log(" task3 complete")
}
log(" task2 status: $task2")
log(task2.await())
log(" task2 status: $task2")
}
log("Start job")
job.join()
log("Program ends")
}
amanda.hinchman-dominguez
01/31/2025, 8:45 PMamanda.hinchman-dominguez
01/31/2025, 8:45 PMStart job | current thread: main
task2 status: DeferredCoroutine{Active}@67117f44 | current thread: main
task1 | current thread: main
task2 | current thread: main
task3 | current thread: main
task1 complete | current thread: main
task2 complete | current thread: main
task3 complete | current thread: main
task2 returned | current thread: main
task2 status: DeferredCoroutine{Completed}@67117f44 | current thread: main
Program ends | current thread: main
amanda.hinchman-dominguez
03/12/2025, 1:05 AMamanda.hinchman-dominguez
03/31/2025, 9:07 PMamanda.hinchman-dominguez
04/09/2025, 5:55 PMamanda.hinchman-dominguez
04/14/2025, 8:15 PMamanda.hinchman-dominguez
04/18/2025, 12:18 AMDariusz Kuc
05/06/2025, 4:43 PM