update for 1.1 beta 17 on the way
Library built upon Kotlin coroutines. Forked from kotlinx.coroutines (kotlinx-coroutines-async), but drops java 8 requirement.
This modification allows libraries to use asnyc and runs under most of Android devices.
Thanks to tikurahul - kotlin-futures implementation.
import async_under8.async
import com.rahulrav.futures.Future
private fun startLongAsyncOperation(v: Int) =
Future.submit {
Thread.sleep(1000)
"Result: $v"
}
fun main(args: Array<String>) {
val future = async<String> {
(1..5).map {
await(startLongAsyncOperation(it))
}.joinToString("\n")
}
future.onSuccess {
println(it)
}
}or depend via Gradle:
compile 'com.fboldog.async_under8:async_under8:0.0.1'or Gradle Kotlin Script:
compile("com.fboldog.async_under8:async_under8:0.0.1")or Maven:
<dependency>
<groupId>com.fboldog.async_under8</groupId>
<artifactId>async_under8</artifactId>
<version>0.0.1</version>
</dependency>