Skip to content

Commit

Permalink
Refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
maksim.zhemerenko authored and Maxim Zhemerenko committed Feb 21, 2024
1 parent 95ffac9 commit 2a01b2a
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import android.content.BroadcastReceiver
import android.content.Context
import android.content.Intent
import android.content.IntentFilter
import com.ionic.plugin.core.utils.wrapSafely
import com.ionic.plugin.core.utils.resumeSafely
import kotlin.coroutines.Continuation
import kotlin.coroutines.suspendCoroutine

Expand All @@ -21,9 +21,7 @@ fun <T> registerContinuationActivityResult(
activityResultObserver.add(object : IActivityResult {
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?): Boolean {
if (!test(requestCode, resultCode, data)) return false
it.wrapSafely {
return@wrapSafely block(requestCode, resultCode, data)
}
it.resumeSafely { block(requestCode, resultCode, data) }
activityResultObserver.remove(this)
return true
}
Expand Down Expand Up @@ -59,6 +57,6 @@ fun <T> registerContinuationReceiver(
block: (intent: Intent) -> T,
) {
registerReceiver(activity, action) { intent ->
it.wrapSafely { block(intent) }
it.resumeSafely { block(intent) }
}
}
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,5 @@ extra.apply {
set("kotlinxAtomicfuVersion", "0.23.2")
set("androidxAppcompatVersion", "1.6.1")
set("mavenGroup", "com.github.SpryRocks.ionic-plugin-core")
set("mavenVersion", "0.1.14-alpha.3")
set("mavenVersion", "0.1.14-alpha.4")
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class ContinuationCallback<T> {
}
}

fun <T> Continuation<T>.wrapSafely(block: () -> T) {
fun <T> Continuation<T>.resumeSafely(block: () -> T) {
try {
if (this.context.isActive) {
resume(block())
Expand Down

0 comments on commit 2a01b2a

Please sign in to comment.