From ca96a46993d4ad6fbd761a8936b5624f76ead926 Mon Sep 17 00:00:00 2001 From: Tonyo Francis Date: Tue, 14 May 2019 11:05:50 -0400 Subject: [PATCH] error handler improvements --- dispatch/src/main/java/com/tonyodev/dispatch/DispatchQueue.kt | 2 +- .../java/com/tonyodev/dispatch/internals/DispatchQueueImpl.kt | 4 ++-- .../java/com/tonyodev/dispatch/internals/DispatchQueueInfo.kt | 3 ++- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/dispatch/src/main/java/com/tonyodev/dispatch/DispatchQueue.kt b/dispatch/src/main/java/com/tonyodev/dispatch/DispatchQueue.kt index 5684aff..de47d50 100644 --- a/dispatch/src/main/java/com/tonyodev/dispatch/DispatchQueue.kt +++ b/dispatch/src/main/java/com/tonyodev/dispatch/DispatchQueue.kt @@ -81,7 +81,7 @@ interface DispatchQueue { * if the dispatch queue object who throw the error does not handle it's error within its doOnError method. The error handler is called on the main thread. * @return dispatch queue. * */ - fun start(errorHandler: ((Throwable, String) -> Unit)?): DispatchQueue + fun start(errorHandler: ((Throwable, DispatchQueue<*>, String) -> Unit)?): DispatchQueue /** * Triggers the dispatch queue to start. diff --git a/dispatch/src/main/java/com/tonyodev/dispatch/internals/DispatchQueueImpl.kt b/dispatch/src/main/java/com/tonyodev/dispatch/internals/DispatchQueueImpl.kt index 2fcf8fa..96022c5 100644 --- a/dispatch/src/main/java/com/tonyodev/dispatch/internals/DispatchQueueImpl.kt +++ b/dispatch/src/main/java/com/tonyodev/dispatch/internals/DispatchQueueImpl.kt @@ -184,7 +184,7 @@ internal class DispatchQueueImpl(override var blockLabel: String, val mainErrorHandler = dispatchQueueInfo.errorHandler if (mainErrorHandler != null) { Threader.getHandlerThreadInfo(ThreadType.MAIN) - .threadHandler.post(Runnable { mainErrorHandler.invoke(throwable, this.blockLabel) }) + .threadHandler.post(Runnable { mainErrorHandler.invoke(throwable, this, this.blockLabel) }) cancel() return } @@ -203,7 +203,7 @@ internal class DispatchQueueImpl(override var blockLabel: String, return start(null) } - override fun start(errorHandler: ((throwable: Throwable, dispatchId: String) -> Unit)?): DispatchQueue { + override fun start(errorHandler: ((throwable: Throwable, dispatchQueue: DispatchQueue<*>, blockLabel: String) -> Unit)?): DispatchQueue { if (!isCancelled) { dispatchQueueInfo.errorHandler = errorHandler dispatchQueueInfo.completedDispatchQueue = false diff --git a/dispatch/src/main/java/com/tonyodev/dispatch/internals/DispatchQueueInfo.kt b/dispatch/src/main/java/com/tonyodev/dispatch/internals/DispatchQueueInfo.kt index 9323c9c..6763eee 100644 --- a/dispatch/src/main/java/com/tonyodev/dispatch/internals/DispatchQueueInfo.kt +++ b/dispatch/src/main/java/com/tonyodev/dispatch/internals/DispatchQueueInfo.kt @@ -1,5 +1,6 @@ package com.tonyodev.dispatch.internals +import com.tonyodev.dispatch.DispatchQueue import com.tonyodev.dispatch.queuecontroller.DispatchQueueController import com.tonyodev.dispatch.utils.Threader import java.util.* @@ -13,7 +14,7 @@ internal class DispatchQueueInfo(val queueId: Int, var completedDispatchQueue = false lateinit var rootDispatchQueue: DispatchQueueImpl<*, *> val queue = LinkedList>() - var errorHandler: ((throwable: Throwable, dispatchId: String) -> Unit)? = null + var errorHandler: ((throwable: Throwable, dispatchQueue: DispatchQueue<*>, blockLabel: String) -> Unit)? = null var dispatchQueueController: DispatchQueueController? = null } \ No newline at end of file