Laxystem
03/10/2025, 4:41 PMCoroutineScope.launch { }.join()
and withContext(CoroutineScope.context) { }
?Joffrey
03/10/2025, 4:49 PMlaunch
starts a concurrent operation, while withContext
just switches the context but runs the piece of code in-place.Laxystem
03/10/2025, 4:50 PM.join()
streetsofboston
03/10/2025, 4:50 PMJoffrey
03/10/2025, 4:51 PMJoffrey
03/10/2025, 4:51 PMLaxystem
03/10/2025, 4:51 PMstreetsofboston
03/10/2025, 4:52 PMJoffrey
03/10/2025, 4:52 PMLaxystem
03/10/2025, 4:52 PMLaxystem
03/10/2025, 4:53 PMJoffrey
03/10/2025, 4:53 PMlaunch { ...}
and join()
. If you chain launch { ... }.join()
, then there is no point in starting a concurrent operation, because no code will effectively run concurrently with itLaxystem
03/10/2025, 4:53 PMLaxystem
03/10/2025, 4:54 PMJoffrey
03/10/2025, 4:54 PMwithContext
in that caseJoffrey
03/10/2025, 4:56 PMI do have a point tho, GLFW (esp. MacOS) threading shenanigansWhat is your point then? Because IMO you can always replace
launch { ... }.join()
with withContext(...) { ... }
Laxystem
03/10/2025, 4:56 PMglfwTerminate
via a SupervisorJob
streetsofboston
03/10/2025, 4:56 PMlaunch {}.join()
only with providing a separate CoroutineScope to the launch
call....streetsofboston
03/10/2025, 4:57 PMotherScope.launch().join()
and you'd call this in yet another CoroutineScope context.streetsofboston
03/10/2025, 4:58 PMcoroutineScope { launch { ... } }
instead, then a join() is not needed (since coroutineScope
only resumes after all its child-coroutines have finished)