aboutsummaryrefslogtreecommitdiff
path: root/app/src
diff options
context:
space:
mode:
authorAllan Wang <me@allanwang.ca>2019-02-02 00:10:27 -0500
committerAllan Wang <me@allanwang.ca>2019-02-02 00:10:27 -0500
commit459359672b1f4266bc0f009c35f246fd90cce36a (patch)
tree41ce6a829a9b31bdc32ab9007d66c313e36985d3 /app/src
parente874b788753ce69ea561b41dc13dfb230c750690 (diff)
downloadfrost-459359672b1f4266bc0f009c35f246fd90cce36a.tar.gz
frost-459359672b1f4266bc0f009c35f246fd90cce36a.tar.bz2
frost-459359672b1f4266bc0f009c35f246fd90cce36a.zip
Fix crash
Diffstat (limited to 'app/src')
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/fragments/RecyclerFragmentBase.kt3
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/views/FrostRecyclerView.kt11
-rw-r--r--app/src/test/kotlin/com/pitchedapps/frost/utils/CoroutineTest.kt45
3 files changed, 50 insertions, 9 deletions
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/fragments/RecyclerFragmentBase.kt b/app/src/main/kotlin/com/pitchedapps/frost/fragments/RecyclerFragmentBase.kt
index 9f26f3f7..37af690b 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/fragments/RecyclerFragmentBase.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/fragments/RecyclerFragmentBase.kt
@@ -30,6 +30,7 @@ import com.pitchedapps.frost.utils.L
import com.pitchedapps.frost.utils.frostJsoup
import com.pitchedapps.frost.views.FrostRecyclerView
import kotlinx.coroutines.Dispatchers
+import kotlinx.coroutines.isActive
import kotlinx.coroutines.withContext
/**
@@ -53,7 +54,7 @@ abstract class RecyclerFragment<T, Item : IItem<*, *>> : BaseFragment(), Recycle
val data = try {
reloadImpl(progress)
} catch (e: Exception) {
- L.e(e) { "Recycler reload fail" }
+ L.e(e) { "Recycler reload fail $baseUrl" }
null
}
withMainContext {
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/views/FrostRecyclerView.kt b/app/src/main/kotlin/com/pitchedapps/frost/views/FrostRecyclerView.kt
index b9fe69d1..ce7437a7 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/views/FrostRecyclerView.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/views/FrostRecyclerView.kt
@@ -27,10 +27,11 @@ import com.pitchedapps.frost.contracts.FrostContentContainer
import com.pitchedapps.frost.contracts.FrostContentCore
import com.pitchedapps.frost.contracts.FrostContentParent
import com.pitchedapps.frost.fragments.RecyclerContentContract
+import com.pitchedapps.frost.utils.L
import com.pitchedapps.frost.utils.Prefs
import kotlinx.coroutines.ExperimentalCoroutinesApi
+import kotlinx.coroutines.isActive
import kotlinx.coroutines.launch
-import kotlinx.coroutines.supervisorScope
/**
* Created by Allan Wang on 2017-05-29.
@@ -75,13 +76,7 @@ class FrostRecyclerView @JvmOverloads constructor(
if (Prefs.animate) fadeOut(onFinish = onReloadClear)
scope.launch {
parent.refreshChannel.offer(true)
- // TODO figure out how to avoid cancelling parent
- try {
- supervisorScope {
- recyclerContract.reload { parent.progressChannel.offer(it) }
- }
- } catch (e: Exception) {
- }
+ recyclerContract.reload { parent.progressChannel.offer(it) }
parent.progressChannel.offer(100)
parent.refreshChannel.offer(false)
if (Prefs.animate) circularReveal()
diff --git a/app/src/test/kotlin/com/pitchedapps/frost/utils/CoroutineTest.kt b/app/src/test/kotlin/com/pitchedapps/frost/utils/CoroutineTest.kt
index fb302648..e93f507c 100644
--- a/app/src/test/kotlin/com/pitchedapps/frost/utils/CoroutineTest.kt
+++ b/app/src/test/kotlin/com/pitchedapps/frost/utils/CoroutineTest.kt
@@ -16,9 +16,11 @@
*/
package com.pitchedapps.frost.utils
+import com.pitchedapps.frost.kotlin.Flyweight
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.GlobalScope
+import kotlinx.coroutines.SupervisorJob
import kotlinx.coroutines.asCoroutineDispatcher
import kotlinx.coroutines.async
import kotlinx.coroutines.channels.BroadcastChannel
@@ -243,4 +245,47 @@ class CoroutineTest {
)
}
}
+
+ @Test
+ fun exceptionChecks() {
+ val mainTag = "main-test"
+ val mainDispatcher = Executors.newSingleThreadExecutor { r ->
+ Thread(r, mainTag)
+ }.asCoroutineDispatcher()
+ val channel = Channel<Int>()
+
+ val job = SupervisorJob()
+
+ val flyweight = Flyweight<Int, Int>(GlobalScope, 200L) {
+ throw java.lang.RuntimeException("Flyweight exception")
+ }
+
+ suspend fun crash(): Boolean = withContext(Dispatchers.IO) {
+ try {
+ withContext(Dispatchers.Default) {
+ flyweight.fetch(0).await()
+ }
+ true
+ } catch (e: java.lang.Exception) {
+ false
+ }
+ }
+
+ runBlocking(mainDispatcher + job) {
+ launch {
+ val i = channel.receive()
+ println("Received $i")
+ }
+ launch {
+ println("A")
+ println(crash())
+ println("B")
+ channel.offer(1)
+ }
+// launch {
+// delay(2000)
+// job.cancel()
+// }
+ }
+ }
}