Skip to content

Commit

Permalink
Merge pull request #18 from inaka/ramabit.only.task
Browse files Browse the repository at this point in the history
Ramabit.variable.parameters
  • Loading branch information
tenmaster committed Jan 22, 2016
2 parents eca376a + bb30ff7 commit a2ccc27
Show file tree
Hide file tree
Showing 7 changed files with 60 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
/**
* Created by inaka on 1/20/16.
*/
public class KillerTaskBlocksTest extends AndroidTestCase {
public class BlocksInsideTest extends AndroidTestCase {

@UiThreadTest
public void testLibraryWithBlocks() {
new ExampleAllTogether();
new ExampleBlocksInside();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
/**
* Created by inaka on 1/21/16.
*/
public class KillerTaskFunctionsTest extends AndroidTestCase {
public class RefactorBlocksTest extends AndroidTestCase {

@UiThreadTest
public void testLibraryFunctionsRefactor() {
new ExampleFunctionsRefactor();
new ExampleBlocksRefactor();
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.inaka.killertask;

import android.test.AndroidTestCase;
import android.test.UiThreadTest;

/**
* Created by inaka on 1/22/16.
*/
public class VariableParametersTest extends AndroidTestCase {

@UiThreadTest
public void testLibraryWithBlocks() {
new ExampleVariableParametersTasks();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import java.util.concurrent.CountDownLatch
/**
* Created by inaka on 1/20/16.
*/
private class ExampleAllTogether {
private class ExampleBlocksInside {
val signal = CountDownLatch(1);

init {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import java.util.concurrent.CountDownLatch
/**
* Created by inaka on 1/21/16.
*/
private class ExampleFunctionsRefactor {
private class ExampleBlocksRefactor {
val signal = CountDownLatch(1);

// onSuccess function
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package com.inaka.killertask

import android.util.Log
import java.util.concurrent.CountDownLatch
import java.util.concurrent.TimeUnit

/**
* Created by inaka on 1/22/16.
*/
private class ExampleVariableParametersTasks {

val signal = CountDownLatch(1);

init {
// 1)
KillerTask({ Log.wtf("LOG", "KillerTask is awesome") }).go() // only main task

// 2)
KillerTask(
{ Log.wtf("LOG", "KillerTask is awesome") }, // main task
{ Log.wtf("LOG", "Super awesome!")} // onSuccess
).go()

// 3)
KillerTask(
{ // main task
Log.wtf("LOG", "KillerTask is awesome")
"super" // implicit return
},
{}, // onSuccess is empty
{ e: Exception? -> Log.wtf("LOG", e.toString()) } // onFailed
).go()

signal.await(5, TimeUnit.SECONDS)
}

}
2 changes: 1 addition & 1 deletion library/src/main/java/com/inaka/killertask/KillerTask.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package com.inaka.killertask
import android.os.AsyncTask
import android.util.Log

class KillerTask<T>(val task: () -> T, val onSuccess: (T) -> Any, val onFailed: (Exception?) -> Any) : AsyncTask<Void, Void, T>() {
class KillerTask<T>(val task: () -> T, val onSuccess: (T) -> Any = {}, val onFailed: (Exception?) -> Any = {}) : AsyncTask<Void, Void, T>() {

private var exception: Exception? = null

Expand Down

0 comments on commit a2ccc27

Please sign in to comment.