Force close app when exception occurs in FutureHelper.

This commit is contained in:
Felix Ableitner 2015-10-29 14:40:04 +01:00
parent a951b05965
commit f5ee0996eb

View file

@ -1,5 +1,7 @@
package com.nutomic.ensichat.core.util
import com.nutomic.ensichat.core.interfaces.Log
import scala.concurrent.{ExecutionContext, Future}
/**
@ -9,11 +11,17 @@ import scala.concurrent.{ExecutionContext, Future}
*/
object FutureHelper {
private val Tag = "FutureHelper"
def apply[A](action: => A)(implicit executor: ExecutionContext): Future[A] = {
val f = Future(action)
f.onFailure {
case e =>
throw e
// HACK: Android does not close app when crash occurs in background thread, and there's no
// cross-platform way to execute on the foreground thread.
// We use this to make sure exceptions are not hidden in the logs.
Log.e(Tag, "Exception in Future", e)
System.exit(-1)
}
f
}