https://github.com/inaka/KillerTask
  
  
    Android AsyncTask wrapper library, written in Kotlin 
    https://github.com/inaka/KillerTask
  
android async kotlin task
        Last synced: 8 months ago 
        JSON representation
    
Android AsyncTask wrapper library, written in Kotlin
- Host: GitHub
- URL: https://github.com/inaka/KillerTask
- Owner: inaka
- License: apache-2.0
- Created: 2016-01-19T14:07:20.000Z (almost 10 years ago)
- Default Branch: master
- Last Pushed: 2017-09-18T18:39:02.000Z (about 8 years ago)
- Last Synced: 2024-10-27T06:39:19.359Z (about 1 year ago)
- Topics: android, async, kotlin, task
- Language: Kotlin
- Homepage:
- Size: 131 KB
- Stars: 26
- Watchers: 39
- Forks: 2
- Open Issues: 1
- 
            Metadata Files:
            - Readme: README.md
- License: LICENSE
 
Awesome Lists containing this project
- awesome-kotlin-android - KillerTask - Android AsyncTask wrapper library, written in Kotlin (Libraries)
- awesome-kotlin - KillerTask - Android AsyncTask wrapper library, written in Kotlin (Libraries)
- awesome-kotlin-libraries-for-android - KillerTask - Android AsyncTask wrapper library, written in Kotlin. (<a name="concurrency"></a>Concurency <sup>[Back ⇈](#contents)</sup>)
README
          KillerTask
=====
This is a Kotlin Android library to create async background tasks. Inspired by [TinyTask](https://github.com/inaka/TinyTask), but more beautiful and easy to use for Kotlin Android developments.
### Abstract
Android's `AsyncTasks` are highly criticized for being bad, unreliable, outdated, etc. Are they perfect? No.
Do we have better alternatives? Sure, but sometimes all we want is a quick and simple way to run something in the background.
### What is it, really?
Just a wrapper around an `AsyncTask`, with a funny looking API.
The main difference between KillerTask and TinyTask is that this library is written in Kotlin language, very different from Java.
To learn how to use Kotlin in your Android app you can visit: [Android development with Kotlin](http://inaka.net/blog/2016/01/15/android-development-with-kotlin)
### How to download and install it
Add the following to your `build.gradle` file:
```groovy
repositories {
	maven {
		url "https://jitpack.io"
	}
}
dependencies {
	// ...
  compile 'com.github.inaka:killertask:v1.2'
  // ...
}
```
### Code examples
```kotlin
    val onSuccess: (String) -> Unit = {
        result: String ->
        Log.wtf("result", result)
    }
    val onFailed: (Exception?) -> Unit = {
        e: Exception? ->
      	Log.wtf("result", e.toString())
    }
    val doWork: () -> String = {
        "test" // implicit return
    }
    var killerTask = KillerTask(doWork, onSuccess, onFailed)
```
```kotlin
    killerTask.go() // to execute it 
```
```kotlin
    killerTask.cancel() // to cancel it
```
Or simply you can do:
```kotlin
    KillerTask(
            { "test" }, // task
            {result: String -> Log.wtf("result", result)}, // onSuccess actions
            {e: Exception? -> Log.wtf("result", e.toString())} // onFailed actions
        ).go()
```
Actually, the only strongly necessary parameter is the first one (the main task):
```kotlin     
    KillerTask({ Log.wtf("LOG", "KillerTask is awesome") }).go() // only main task
```
```kotlin  
    KillerTask(
            { Log.wtf("LOG", "KillerTask is awesome") }, // main task
            { Log.wtf("LOG", "Super awesome!")} // onSuccess
    ).go()
```
```kotlin 
    KillerTask(
            { // main task
                Log.wtf("LOG", "KillerTask is awesome")
                "super" // implicit return
            },
            {}, // onSuccess is empty
            { e: Exception? -> Log.wtf("LOG", e.toString()) } // onFailed
    ).go()
```
### Example of an app using KillerTask
* [Kotlillon](https://github.com/inaka/kotlillon)
### Contact Us
If you find any **bugs** or have a **problem** while using this library, please [open an issue](https://github.com/inaka/KillerTask/issues/new) in this repo (or a pull request :)).