Skip to content

Commit 00560e8

Browse files
committed
rx-example: Added application plugin & fixed to use runBlocking
1 parent 727331c commit 00560e8

File tree

2 files changed

+18
-14
lines changed

2 files changed

+18
-14
lines changed

reactive/kotlinx-coroutines-rx-example/build.gradle

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
2+
apply plugin: 'application'
3+
4+
mainClassName = 'MainKt'
5+
16
dependencies {
27
ext.retrofit_version = '2.3.0'
38
compile project(':kotlinx-coroutines-rx2')

reactive/kotlinx-coroutines-rx-example/src/main/kotlin/main.kt

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,7 @@
1515
*/
1616

1717
import io.reactivex.Single
18-
import kotlinx.coroutines.experimental.CommonPool
19-
import kotlinx.coroutines.experimental.launch
18+
import kotlinx.coroutines.experimental.*
2019
import kotlinx.coroutines.experimental.rx2.await
2120
import retrofit2.Retrofit
2221
import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory
@@ -38,7 +37,9 @@ interface GitHub {
3837
data class Contributor(val login: String, val contributions: Int)
3938
data class Repo(val name: String)
4039

41-
fun main(args: Array<String>) {
40+
fun main(args: Array<String>) = runBlocking {
41+
println("Making GitHub API request")
42+
4243
val retrofit = Retrofit.Builder().apply {
4344
baseUrl("https://api.github.com")
4445
addConverterFactory(GsonConverterFactory.create())
@@ -47,19 +48,17 @@ fun main(args: Array<String>) {
4748

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

50-
launch(CommonPool) {
51-
val contributors =
52-
github.contributors("JetBrains", "Kotlin")
53-
.await().take(10)
51+
val contributors =
52+
github.contributors("JetBrains", "Kotlin")
53+
.await().take(10)
5454

55-
for ((name, contributions) in contributors) {
56-
println("$name has $contributions contributions, other repos: ")
55+
for ((name, contributions) in contributors) {
56+
println("$name has $contributions contributions, other repos: ")
5757

58-
val otherRepos =
59-
github.listRepos(name).await()
60-
.map(Repo::name).joinToString(", ")
58+
val otherRepos =
59+
github.listRepos(name).await()
60+
.map(Repo::name).joinToString(", ")
6161

62-
println(otherRepos)
63-
}
62+
println(otherRepos)
6463
}
6564
}

0 commit comments

Comments
 (0)