Skip to content

Commit

Permalink
BUGFIX update coroutines to 1.6.3
Browse files Browse the repository at this point in the history
Fixes a DiskRead policy violation (really this time)
  • Loading branch information
ninovanhooff committed Jun 22, 2022
1 parent 9cc3c55 commit d0e8508
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 24 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
buildscript {
ext {
kotlin_version = "1.6.10"
version_kotlinx_coroutines = "1.6.0"
version_kotlinx_coroutines = "1.6.3"
gradle_version = '7.1.2'
jvm_target = "11"
version_androidx_annotation = "1.2.0"
Expand Down
29 changes: 6 additions & 23 deletions q42stats/src/main/java/com/q42/q42stats/library/Q42Stats.kt
Original file line number Diff line number Diff line change
Expand Up @@ -21,31 +21,14 @@ internal const val DATA_MODEL_VERSION = 3
class Q42Stats(private val config: Q42StatsConfig) {

/**
* Collects stats and sends it to the server. This method is safe to be called from anywhere
* in your app and will do nothing if it is running or has already run before
* Collects stats and sends it to the server. This method is safe to be called from anywhere
* in your app and will do nothing if it is running or has already run before
*/
@OptIn(DelicateCoroutinesApi::class)
@AnyThread
fun runAsync(context: Context) {
// Creating MainScope on the main thread would trigger a diskRead violation, so go to IO
CoroutineScope(Dispatchers.IO + coroutineExceptionHandler).launch {
runAsync(context, MainScope() + coroutineExceptionHandler)
}
}

/**
* Collects stats and sends it to the server. This method can be called from anywhere
* in your app and will do nothing if it is running or has already run before.
*
* Although this overload is generally safe;
* Consider using [runAsync] instead for maximum error handling safety
*
* @param coroutineScope should be configured with an CoroutineExceptionHandler
*
*/
@AnyThread
@DelicateCoroutinesApi
fun runAsync(context: Context, coroutineScope: CoroutineScope) {
fun runAsync(
context: Context,
coroutineScope: CoroutineScope = MainScope() + coroutineExceptionHandler
) {
Q42StatsLogger.d(TAG, "Q42Stats: Checking Preconditions")
// check preconditions on the main thread to prevent concurrency issues
coroutineScope.launch(Dispatchers.Main) {
Expand Down

0 comments on commit d0e8508

Please sign in to comment.