Skip to content

Commit

Permalink
error handler improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
tonyofrancis committed May 14, 2019
1 parent 721ccb2 commit ca96a46
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ interface DispatchQueue<R> {
* 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<R>
fun start(errorHandler: ((Throwable, DispatchQueue<*>, String) -> Unit)?): DispatchQueue<R>

/**
* Triggers the dispatch queue to start.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ internal class DispatchQueueImpl<T, R>(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
}
Expand All @@ -203,7 +203,7 @@ internal class DispatchQueueImpl<T, R>(override var blockLabel: String,
return start(null)
}

override fun start(errorHandler: ((throwable: Throwable, dispatchId: String) -> Unit)?): DispatchQueue<R> {
override fun start(errorHandler: ((throwable: Throwable, dispatchQueue: DispatchQueue<*>, blockLabel: String) -> Unit)?): DispatchQueue<R> {
if (!isCancelled) {
dispatchQueueInfo.errorHandler = errorHandler
dispatchQueueInfo.completedDispatchQueue = false
Expand Down
Original file line number Diff line number Diff line change
@@ -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.*
Expand All @@ -13,7 +14,7 @@ internal class DispatchQueueInfo(val queueId: Int,
var completedDispatchQueue = false
lateinit var rootDispatchQueue: DispatchQueueImpl<*, *>
val queue = LinkedList<DispatchQueueImpl<*, *>>()
var errorHandler: ((throwable: Throwable, dispatchId: String) -> Unit)? = null
var errorHandler: ((throwable: Throwable, dispatchQueue: DispatchQueue<*>, blockLabel: String) -> Unit)? = null
var dispatchQueueController: DispatchQueueController? = null

}

0 comments on commit ca96a46

Please sign in to comment.