Skip to content

Commit

Permalink
rx-example: Added application plugin & fixed to use runBlocking
Browse files Browse the repository at this point in the history
  • Loading branch information
elizarov committed Mar 5, 2018
1 parent 727331c commit 00560e8
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 14 deletions.
5 changes: 5 additions & 0 deletions reactive/kotlinx-coroutines-rx-example/build.gradle
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@

apply plugin: 'application'

mainClassName = 'MainKt'

dependencies {
ext.retrofit_version = '2.3.0'
compile project(':kotlinx-coroutines-rx2')
Expand Down
27 changes: 13 additions & 14 deletions reactive/kotlinx-coroutines-rx-example/src/main/kotlin/main.kt
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@
*/

import io.reactivex.Single
import kotlinx.coroutines.experimental.CommonPool
import kotlinx.coroutines.experimental.launch
import kotlinx.coroutines.experimental.*
import kotlinx.coroutines.experimental.rx2.await
import retrofit2.Retrofit
import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory
Expand All @@ -38,7 +37,9 @@ interface GitHub {
data class Contributor(val login: String, val contributions: Int)
data class Repo(val name: String)

fun main(args: Array<String>) {
fun main(args: Array<String>) = runBlocking {
println("Making GitHub API request")

val retrofit = Retrofit.Builder().apply {
baseUrl("https://api.github.com")
addConverterFactory(GsonConverterFactory.create())
Expand All @@ -47,19 +48,17 @@ fun main(args: Array<String>) {

val github = retrofit.create(GitHub::class.java)

launch(CommonPool) {
val contributors =
github.contributors("JetBrains", "Kotlin")
.await().take(10)
val contributors =
github.contributors("JetBrains", "Kotlin")
.await().take(10)

for ((name, contributions) in contributors) {
println("$name has $contributions contributions, other repos: ")
for ((name, contributions) in contributors) {
println("$name has $contributions contributions, other repos: ")

val otherRepos =
github.listRepos(name).await()
.map(Repo::name).joinToString(", ")
val otherRepos =
github.listRepos(name).await()
.map(Repo::name).joinToString(", ")

println(otherRepos)
}
println(otherRepos)
}
}

0 comments on commit 00560e8

Please sign in to comment.