Start on attach coroutine immediately

This commit is contained in:
Suphon Thanakornpakapong
2022-05-25 20:05:30 +07:00
parent 4fc76c3639
commit 3cbf366fb5
@@ -11,7 +11,10 @@ fun View.repeatOnAttached(block: suspend CoroutineScope.() -> Unit) {
val mutext = Mutex()
observeAttachedState { isAttached ->
if (isAttached) {
launchedJob = MainScope().launch(Dispatchers.Main.immediate) {
launchedJob = MainScope().launch(
context = Dispatchers.Main.immediate,
start = CoroutineStart.UNDISPATCHED
) {
mutext.withLock {
coroutineScope {
block()