All Downloads are FREE. Search and download functionalities are using the official Maven repository.

android.os.AsyncTask.kt Maven / Gradle / Ivy

Go to download

The Firebase Java SDK is a pure java port of the Firebase Android SDK to run in clientside java environments such as the desktop.

The newest version!
package android.os

import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import java.util.concurrent.Executor

abstract class AsyncTask {

    companion object {
        @JvmField
        val THREAD_POOL_EXECUTOR = Executor {
            GlobalScope.launch {
                it.run()
            }
        }
    }

    fun execute(vararg params: Any): AsyncTask {
        GlobalScope.launch {
            withContext(Dispatchers.Main) { onPreExecute() }
            val result = doInBackground(*params)
            withContext(Dispatchers.Main) { onPostExecute(result) }
        }
        return this
    }

    protected abstract fun doInBackground(vararg params: Any): Any

    protected open fun onPreExecute() {}

    protected open fun onPostExecute(result: Any) {}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy