Minor. Update README.md
1 file changed
tree: 96d914cb2ceb0bd5cc573fa5f774eb8c4e82a0a7
  1. kotlinx-coroutines-async/
  2. kotlinx-coroutines-async-example-ui/
  3. kotlinx-coroutines-generate/
  4. .gitignore
  5. pom.xml
  6. README.md
README.md

kotlinx.coroutines

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 package
  • kotlinx-coroutines-generate provides ability to create Sequence objects generated by coroutine body containing yield suspension points

Examples

Async

import 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())
}

Generate

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.

Maven

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-alpha-1</version>
</dependency>

Gradle

Just add a dependency:

compile 'org.jetbrains.kotlinx:kotlinx-coroutines-generate:0.1-alpha-1'

Also you should include our bintray repository:

repositories {
    maven {
        url "http://dl.bintray.com/kotlin/kotlinx.coroutines"
    }
}