-
Notifications
You must be signed in to change notification settings - Fork 371
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2233 from OneSignal/fix-ANR-operationRepo-load-wi…
…th-coroutine-enqueue Fix ANR caused by operationRepo.enqueue while loading is in progress
- Loading branch information
Showing
4 changed files
with
103 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
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