commit | 1d2eb9038af7c86253818825bad72d4a2c79dbd0 | [log] [tgz] |
---|---|---|
author | Denis Zharkov <denis.zharkov@jetbrains.com> | Wed Jun 22 19:21:32 2016 +0300 |
committer | Denis Zharkov <denis.zharkov@jetbrains.com> | Wed Jun 22 19:21:32 2016 +0300 |
tree | c59abbac437584b2e8da6e9059fe1438f54608cd | |
parent | 8e4e0e45d03dedb25626ca2af4997fec0608af95 [diff] |
Minor. Rename asyncUi -> asyncUI
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>central</id> <name>bintray</name> <url>http://jcenter.bintray.com</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 { jcenter() }