Android AsyncTask wrapper library, written in Kotlin

Overview

KillerTask

This is a Kotlin Android library to create async background tasks. Inspired by 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

How to download and install it

Add the following to your build.gradle file:

repositories {
	maven {
		url "https://jitpack.io"
	}
}

dependencies {
	// ...
  compile 'com.github.inaka:killertask:v1.2'
  // ...
}

Code examples

    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)
    killerTask.go() // to execute it 
    killerTask.cancel() // to cancel it

Or simply you can do:

    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):

    KillerTask({ Log.wtf("LOG", "KillerTask is awesome") }).go() // only main task
    KillerTask(
            { Log.wtf("LOG", "KillerTask is awesome") }, // main task
            { Log.wtf("LOG", "Super awesome!")} // onSuccess
    ).go()
    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

Contact Us

If you find any bugs or have a problem while using this library, please open an issue in this repo (or a pull request :)).

You might also like...
🎲 A powerful and simple-to-use guilded wrapper made in Kotlin.

🎲 deck [WIP] Deck is a powerful yet simple-to-use guilded wrapper made entirely in Kotlin with support to multiplatform. Implementating In case you'r

Wrapper of FusedLocationProviderClient for Android to support modern usage like LiveData and Flow

FancyLocationProvider Wrapper of FusedLocationProviderClient for Android to support modern usage like LiveData or Flow. Install Add Jitpack repository

Permissionmanager is a small wrapper for handling permission requests.

Permissionmanager Permissionmanager is a small wrapper for handling permission requests. Installation Add jitpack to your repositories in Project buil

🧸 A multiplatform coroutine-based wrapper for popular platform-specific Redis client libraries

🧸 rekt ⚠️ WARNING! This project is experimental and may be missing essential features. Please let us know if you found any issues or have any suggest

🧸 A multiplatform coroutine-based wrapper for popular platform-specific Redis client libraries

🧸 rekt ⚠️ WARNING! This project is experimental and may be missing essential features. Please let us know if you found any issues or have any suggest

A lightweight cache library written in Kotlin

[NEW] Released to Maven Central: 'com.github.yundom:kache:1.x.x' Kache A runtime in-memory cache. Installation Put this in your build.gradle implemen

A fast, lightweight, entity component system library written in Kotlin.

Fleks A fast, lightweight, entity component system library written in Kotlin. Motivation When developing my hobby games using LibGDX, I always used As

Sample Code for fake Kotlin library written in Java

Jatlin このリポジトリは ブログ記事 のためのサンプルコードです。詳細は記事をご覧ください。 プロジェクト構成 :java-lib にKotlinに偽装したJavaファイルが含まれます。 :kotlin-lib は :java-lib をビルドしたJARファイルをKotlinから読み込んで実行

A property/method accessor library for the JVM, written in Kotlin

unlok - unlock your JVM a property/method accessor library for the JVM, written in Kotlin. how to import you can import unlok from maven central just

Comments
  • Check double call

    Check double call

    Check if when the first parameter of KillerTask (the task to do) is called by a function call, this function is being executed twice (one in the main thread at that moment, another one in the separate thread when killerTask.go() is called)

    possible_bug 
    opened by ramabit 1
  • Fulfil the open-source checklist

    Fulfil the open-source checklist

    General Items

    • [x] It has a github repo
    • [x] It has a proper Apache2 LICENSE file
    • [x] It's has a clear and useful README.md
    • [x] It's documented (with examples)
    • [x] It's tested
    • [x] It's hooked to a the open-source hipchat room
    • [x] It has a link to the open-source hipchat room in its README
    • [x] It has a link to inaka.github.io in its README and/or landing page

    Exhibition

    • [x] There is a blog post about it
    • [x] It's shared on social networks
    • [x] It's shared on reddit
    • [x] It's shared on hacker news with a title like Show HN: description

    For Libraries

    • [x] It provides a sample application
    • [x] Examples of use are documented in the README or linked from there
    opened by elbrujohalcon 1
Releases(v1.4)
Owner
Inaka
Inaka
A Kotlin DSL wrapper around the mikepenz/MaterialDrawer library.

MaterialDrawerKt Create navigation drawers in your Activities and Fragments without having to write any XML, in pure Kotlin code, with access to all t

Márton Braun 517 Nov 19, 2022
This library is a set of simple wrapper classes that are aimed to help you easily access android device information.

SysInfo Simple, single class wrapper to get device information from an android device. This library provides an easy way to access all the device info

Klejvi Kapaj 7 Dec 27, 2022
Dependency Injection library for Compose Multiplatform, Koin wrapper.

?? Cokoin Injection library for Compose (Multiplatform and Jetpack), Koin wrapper. It uses @Composable functions to configure KoinContext and Scopes.

Bruno Wieczorek 57 Dec 29, 2022
A lightweight Kotlin friendly wrapper around Couchbase lite for Android.

CouchBaseKtx ?? Work In-Progress ?? A lightweight Kotlin friendly wrapper around Couchbase-lite for Android Read up a little bit of documentation abou

Jaya Surya Thotapalli 5 Feb 15, 2022
A simple Kotlin wrapper around Anvil.

AnvilKotlin A simple Kotlin wrapper around Anvil. The only purpose of this library is to provide type safety to Anvil through Kotlin. Nothing more, no

Andre Artus 15 Oct 3, 2022
Netflix inspired OTT Home Screen, Contains implementation in Reactjs, Kotlin React Wrapper, Jetpack Compose Web

Netflix-Clone-React Practising React by building Netflix Clone Requirements TMDB api key : Add TMDB API key to AppApi.kt Learning Resourcce Build Netf

Chetan Gupta 61 Nov 13, 2022
A Kotlin coroutines wrapper for IndexedDB.

Kotlin IndexedDB A wrapper around IndexedDB which allows for access from Kotlin/JS code using suspend blocks and linear, non-callback based control fl

JUUL Labs 10 Dec 11, 2022
Yaspeller-kt - Asynchronous Yandex.Speller API wrapper for Kotlin/JVM.

yaspeller-kt Asynchronous Yandex.Speller API wrapper for Kotlin/JVM. Installation repositories { maven { url 'https://jitpack.io' }

Mikhail Koshkin 6 Jun 27, 2022
⏰ A powerful and simple-to-use guilded wrapper made in Kotlin.

⏰ guilded-kt [WIP] A powerful yet simple-to-use guilded wrapper made entirely in Kotlin with supporting multiplatform. Take a look at an example of th

Gabriel 13 Jul 30, 2022
SavedStateFlow - A Kotlin StateFlow wrapper around SavedStateHandle

SavedStateFlow SavedStateFlow is a Kotlin StateFlow wrapper around SavedStateHan

Andrew Steinmetz 13 Aug 4, 2022