Jérôme Gully
11/07/2019, 10:45 PMGlobalScope.launch { }
to run an infinite while to draw on canvas (Android SurfaceView) or it is a better solution ?zak.taccardi
11/07/2019, 10:46 PMJérôme Gully
11/07/2019, 10:47 PMzak.taccardi
11/07/2019, 10:47 PMJérôme Gully
11/07/2019, 10:47 PMzak.taccardi
11/07/2019, 10:48 PMlateinit var onCreateScope: CoroutineScope
fun onCreate(){
onCreateScope = CoroutineScope(Dispatchers.Main)
}
fun onDestroy() {
onCreateScope.cancel()
}
Jérôme Gully
11/07/2019, 10:48 PMjob
propertie and I can directly call surfaceViewScope.cancel()
in surfaceDestroyed()
, if I'm right 🙂zak.taccardi
11/07/2019, 10:52 PMJérôme Gully
11/07/2019, 10:56 PMSurfaceView
, I was been able to define directly my propertie on declaration with private val surfaceViewScope = CoroutineScope(Dispatchers.Default)
, I guess it's right 😬zak.taccardi
11/07/2019, 10:59 PMJérôme Gully
11/07/2019, 10:59 PMzak.taccardi
11/07/2019, 11:00 PMDispatchers.Default
is a thread pool, so if you launch more than one coroutine you lose thread safety (any code confined to a single coroutine is thread safe, even if it runs across multiple threads)Jérôme Gully
11/07/2019, 11:04 PMIO
dispatcher ?zak.taccardi
11/07/2019, 11:16 PMIO
dispatcher is for blocking calls that don’t do any work while they block a thread