commit | 81bb04acfa16f7e2a653856f3f6d4b685917c9b2 | [log] [tgz] |
---|---|---|
author | Denis Zharkov <denis.zharkov@jetbrains.com> | Wed Jul 06 16:13:36 2016 +0300 |
committer | Denis Zharkov <denis.zharkov@jetbrains.com> | Wed Jul 06 16:13:36 2016 +0300 |
tree | 40cdf4cf777999720a3bacd77fb7ee6809386692 | |
parent | 94e787967a95df578f88d23e4f9465222a1ef1ba [diff] |
Update README.md
Two libraries built upon Kotlin coroutines:
kotlinx-coroutines-async
with convenient interfaces/wrappers to commonly used asynchronous API shipped with standard JDK, namely promise-like CompletableFuture
and asynchronous channels from java.nio
packagekotlinx-coroutines-generate
provides ability to create Sequence
objects generated by coroutine body containing yield
suspension pointsimport kotlinx.coroutines.async import java.util.concurrent.CompletableFuture private fun startLongAsyncOperation(v: Int) = CompletableFuture.supplyAsync { Thread.sleep(1000) "Result: $v" } fun main(args: Array<String>) { val future = async<String> { (1..5).map { await(startLongAsyncOperation(it)) }.joinToString("\n") } println(future.get()) }
Bear in mind that async
library actively uses CompletableFuture
from JDK 8, so it will not work with earlier versions.
import kotlinx.coroutines.generate fun main(args: Array<String>) { val sequence = generate<Int> { for (i in 1..5) { yield(i) } } println(sequence.joinToString(" ")) }
For more examples you can look at kotlinx-coroutines-async-example-ui
sample project or in tests directories.
Add the bintray repository
<repository> <snapshots> <enabled>false</enabled> </snapshots> <id>dl</id> <name>bintray</name> <url>http://dl.bintray.com/kotlin/kotlinx.coroutines</url> </repository>
Add dependencies:
<dependency> <groupId>org.jetbrains.kotlinx</groupId> <artifactId>kotlinx-coroutines-generate</artifactId> <version>0.1-alpha-1</version> </dependency> <dependency> <groupId>org.jetbrains.kotlinx</groupId> <artifactId>kotlinx-coroutines-async</artifactId> <version>0.1-alpha-1</version> </dependency>
Just add dependencies:
compile 'org.jetbrains.kotlinx:kotlinx-coroutines-generate:0.1-alpha-1' compile 'org.jetbrains.kotlinx:kotlinx-coroutines-async:0.1-alpha-1'
NB: As async
library is built upon CompletableFuture
it requires JDK 8 (24 Android API level)
Also you should include our bintray repository:
repositories { maven { url "http://dl.bintray.com/kotlin/kotlinx.coroutines" } }