Skip to content

Commit

Permalink
Fix to ambigous start method
Browse files Browse the repository at this point in the history
  • Loading branch information
tonyofrancis committed Jun 14, 2019
1 parent 2d94e2d commit 72d007b
Show file tree
Hide file tree
Showing 8 changed files with 23 additions and 31 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
Version 1.4.8
- Remove ambiguous start method

Version 1.4.7
- Fixed issue where a cancelled queue would throw exceptions

Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[ ![Download](https://api.bintray.com/packages/tonyofrancis/maven/dispatch/images/download.svg?version=1.4.7) ](https://bintray.com/tonyofrancis/maven/dispatch/1.4.7/link)
[ ![Download](https://api.bintray.com/packages/tonyofrancis/maven/dispatch/images/download.svg?version=1.4.8) ](https://bintray.com/tonyofrancis/maven/dispatch/1.4.8/link)
# DispatchQueue: A simple work scheduler for Java, Kotlin and Android

DispatchQueue is a simple and flexible work scheduler that schedulers work on a background or main thread in the form of a dispatch queue.
Expand Down Expand Up @@ -378,15 +378,15 @@ The above is a simple diagram on how a dispatch queue works. When you create a q

To use the DispatchQueue library in your project, add the following code to your project’s build.gradle file.
```java
implementation "com.tonyodev.dispatch:dispatch:1.4.7"
implementation "com.tonyodev.dispatch:dispatch:1.4.8"
```
For Android also add:
```java
implementation "com.tonyodev.dispatch:dispatch-android:1.4.7"
implementation "com.tonyodev.dispatch:dispatch-android:1.4.8"
```
To use Dispatch with Retrofit, add:
```java
implementation "com.tonyodev.dispatch:dispatch-retrofit2-adapter:1.4.7"
implementation "com.tonyodev.dispatch:dispatch-retrofit2-adapter:1.4.8"
```

Android users also have to initialize the AndroidDispatchQueues on application launch.
Expand Down
9 changes: 7 additions & 2 deletions app/src/main/java/com/tonyodev/dispatcherapp/ActivityTwo.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import com.tonyodev.dispatch.DispatchQueue;
import com.tonyodev.dispatch.DispatchQueueError;
import com.tonyodev.dispatch.DispatchQueueErrorCallback;
import com.tonyodev.dispatch.queuecontroller.CancelType;
import com.tonyodev.dispatchandroid.queueController.ActivityDispatchQueueController;
import kotlin.jvm.functions.Function1;
Expand Down Expand Up @@ -44,9 +46,12 @@ private void runIntervalTask() {
}).async((Function1<Void, Void>) aVoid -> {
Log.d("dispatcherTest", "void method called");
return null;
}).start(dispatchQueueError -> {
}).start(new DispatchQueueErrorCallback() {
@Override
public void onError(DispatchQueueError dispatchQueueError) {

});
}
});
}

}
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

buildscript {
ext.kotlin_version = '1.3.31'
ext.library_version = '1.4.7'
ext.library_version_code = 23
ext.library_version = '1.4.8'
ext.library_version_code = 24
ext.retrofit_version = '2.5.0'
ext.gson_version = '2.8.5'
ext.novoda_bintray_version = '0.9'
Expand Down
8 changes: 0 additions & 8 deletions dispatch/src/main/java/com/tonyodev/dispatch/DispatchQueue.kt
Original file line number Diff line number Diff line change
Expand Up @@ -97,14 +97,6 @@ interface DispatchQueue<R> {
* */
fun start(): DispatchQueue<R>

/**
* Triggers the dispatch queue to start.
* @param errorCallback the error handler for the dispatch queue. Notifies of the async or post block via its label that throw the error and the error that was thrown. Only called
* 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(errorCallback: (DispatchQueueError) -> Unit): DispatchQueue<R>

/**
* Cancels all pending work on the dispatch queue.
* Once cancelled a dispatch queue cannot start again.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,13 +179,8 @@ internal class DispatchQueueImpl<T, R>(override var blockLabel: String,
private fun handleException(throwable: Throwable) {
val mainErrorHandler = dispatchQueueInfo.dispatchQueueErrorCallback
if (mainErrorHandler != null) {
Threader.getHandlerThreadInfo(ThreadType.MAIN)
.threadHandler.post(Runnable {
if (mainErrorHandler is DispatchQueueErrorCallback) {
mainErrorHandler.onError(DispatchQueueError(throwable, this, this.blockLabel))
} else {
(mainErrorHandler as (DispatchQueueError) -> Unit).invoke(DispatchQueueError(throwable, this, this.blockLabel))
}
Threader.getHandlerThreadInfo(ThreadType.MAIN).threadHandler.post(Runnable {
mainErrorHandler.onError(DispatchQueueError(throwable, this, this.blockLabel))
})
cancel()
return
Expand Down Expand Up @@ -216,15 +211,11 @@ internal class DispatchQueueImpl<T, R>(override var blockLabel: String,
return startQueue(null)
}

override fun start(errorCallback: (DispatchQueueError) -> Unit): DispatchQueue<R> {
return startQueue(errorCallback)
}

override fun start(dispatchQueueErrorCallback: DispatchQueueErrorCallback?): DispatchQueue<R> {
return startQueue(dispatchQueueErrorCallback)
}

private fun startQueue(errorCallback: Any?): DispatchQueue<R> {
private fun startQueue(errorCallback: DispatchQueueErrorCallback?): DispatchQueue<R> {
if (!isCancelled) {
if (!dispatchQueueInfo.isStarted) {
dispatchQueueInfo.isStarted = true
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.DispatchQueueErrorCallback
import com.tonyodev.dispatch.queuecontroller.DispatchQueueController
import com.tonyodev.dispatch.utils.Threader

Expand All @@ -10,7 +11,7 @@ internal class DispatchQueueInfo(val queueId: Int,
var isCancelled = false
@Volatile
var isStarted = false
var dispatchQueueErrorCallback: Any? = null
var dispatchQueueErrorCallback: DispatchQueueErrorCallback? = null
var dispatchQueueController: DispatchQueueController? = null
var rootDispatchQueue: DispatchQueueImpl<*, *>? = null
var endDispatchQueue: DispatchQueueImpl<*, *>? = null
Expand Down
4 changes: 2 additions & 2 deletions dispatch/src/main/java/com/tonyodev/dispatch/utils/Consts.kt
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package com.tonyodev.dispatch.utils

import com.tonyodev.dispatch.DispatchQueueError
import com.tonyodev.dispatch.DispatchQueueErrorCallback

const val TAG = "DispatchQueue"
internal val INVALID_RESULT = InvalidResult()
internal val CANCELLED_ERROR_CALLBACK = {_: DispatchQueueError -> }
internal val CANCELLED_ERROR_CALLBACK = DispatchQueueErrorCallback { }
const val THREAD_BACKGROUND = "DispatchQueueBackground"
const val THREAD_IO = "DispatchQueueIO"
const val THREAD_TEST = "DispatchQueueTest"
Expand Down

0 comments on commit 72d007b

Please sign in to comment.