-
Notifications
You must be signed in to change notification settings - Fork 370
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: ANR caused by operationRepo.enqueue while loading is not complete
Making the enqueue logic to be done in the background
- Loading branch information
1 parent
fc48c72
commit 0de1885
Showing
3 changed files
with
39 additions
and
10 deletions.
There are no files selected for viewing
19 changes: 19 additions & 0 deletions
19
...DK/onesignal/core/src/main/java/com/onesignal/common/threading/OSPrimaryCoroutineScope.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package com.onesignal.common.threading | ||
|
||
import kotlinx.coroutines.CoroutineScope | ||
import kotlinx.coroutines.launch | ||
import kotlinx.coroutines.newSingleThreadContext | ||
|
||
object OSPrimaryCoroutineScope { | ||
// CoroutineScope tied to the main thread | ||
private val mainScope = CoroutineScope(newSingleThreadContext(name = "OSPrimaryCoroutineScope")) | ||
|
||
/** | ||
* Executes the given [block] on the OS primary coroutine scope. | ||
*/ | ||
fun execute(block: suspend () -> Unit) { | ||
mainScope.launch { | ||
block() | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters