commit | c4c61d13a9fafa682579d1080aa44ac17f0e725b | [log] [tgz] |
---|---|---|
author | Denis Zharkov <denis.zharkov@jetbrains.com> | Thu Jun 23 10:48:40 2016 +0300 |
committer | Denis Zharkov <denis.zharkov@jetbrains.com> | Thu Jun 23 10:48:40 2016 +0300 |
tree | 8a7e517c2d3d82629caca1cefb6090a13a972472 | |
parent | 64970a4c1c4ccf08801c4dcc79354760582266b2 [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()) }
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 jcenter repository (if you don't have it yet)
<repository> <snapshots> <enabled>false</enabled> </snapshots> <id>dl</id> <name>bintray</name> <url>http://dl.bintray.com/kotlin/kotlinx.coroutines</url> </repository>
Add a dependency:
<dependency> <groupId>org.jetbrains.kotlinx</groupId> <artifactId>kotlinx-coroutines-generate</artifactId> <version>0.1</version> </dependency>
Just add a dependency:
compile 'org.jetbrains.kotlinx:kotlinx-coroutines-generate:0.1'
jcenter repository should be configured by default in gradle, but if it's not you may need to include it:
repositories { maven { url "http://dl.bintray.com/kotlin/kotlinx.coroutines" } }