NeoTask is an extension library that treats Tasks API smarter. For example, you can greatly simplify the code to perform asynchronous processing of the Tasks API in serial or parallel, or create Custom Task easily.
-
You can use Tasks API greatly smart, especially parallel or series execution.
-
Tasks API allows nullable result, but NeoTask does not allow nullable result, just like RxJava2. And you can easily convert from nullable result task to non-null result task using this library.
-
NeoTask is a lightweight library, so you can easily try out, and install.
-
Android SDK API Level 14 or more
-
Android Project written in Kotlin
- Android Project using Firebase and Kotlin
Recommend to see the Firebase blog posts or Google I/O 2016 YouTube.
-
https://firebase.googleblog.com/2016/09/become-a-firebase-taskmaster-part-1.html
-
https://firebase.googleblog.com/2016/09/become-a-firebase-taskmaster-part-2.html
-
https://firebase.googleblog.com/2016/09/become-a-firebase-taskmaster-part-3_29.html
-
https://firebase.googleblog.com/2016/10/become-a-firebase-taskmaster-part-4.html
Tasks API Guides from Google.
FirebaseAuth.getInstance().signInAnonymously()
.then { it.user.getIdToken(false) }
.addOnCompleteListener(this, {
if (it.isSuccessful) {
val result = it.result
// Do something
}
else {
val exception = it.exception
// Do something
}
})
NeoTask.async { "result" }
.thenAsync {
listOf(it, "result2").joinToString(separator = ",")
}
.addOnCompleteListener(this, {
if (it.isSuccessful) {
val result = it.result
// Do something
}
else {
val exception = it.exception
// Do something
}
})
NeoTask.parallel(
FirebaseFirestore.getInstance().collection("restaurants").add(restaurant1),
FirebaseFirestore.getInstance().collection("users").add(user),
FirebaseFirestore.getInstance().collection("settings").add(setting)
).addOnSuccessListener(this, {
val result = "${it.first}, ${it.second}, ${it.third}"
// Do something
})
.addOnFailureListener(this, {
val exception = it
// Do something
})
NeoTask.whenAll(
NeoTask.async { "result1" },
NeoTask.async { "result2" },
NeoTask.async { "result3" },
NeoTask.async { "result4" },
NeoTask.async { "result5" })
.addOnSuccessListener(this, {
val result = "${it.first}, ${it.second}, ${it.third}, ${it.fourth}, ${it.five}"
// Do something
})
.addOnFailureListener(this, {
val exception = it
// Do something
})
val idToken = NeoTask.await(firebaseUser.getIdToken(false), AwaitTimeOut.seconds(30))
val logging = NeoTask.awaitSequential(
firebaseUser.getIdToken(false),
{ NeoTask.async { "token: " + it.token } })
If you wants to learn more, see also the sample project this repo.
allprojects {
repositories {
maven { url "https://jitpack.io" }
}
}
dependencies {
implementation("com.github.tatuas:NeoTask:$latest_version") {
transitive = true
}
}
Copyright (C) 2017 Tatsuya Sawai
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.