15
15
*/
16
16
17
17
import io.reactivex.Single
18
- import kotlinx.coroutines.experimental.CommonPool
19
- import kotlinx.coroutines.experimental.launch
18
+ import kotlinx.coroutines.experimental.*
20
19
import kotlinx.coroutines.experimental.rx2.await
21
20
import retrofit2.Retrofit
22
21
import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory
@@ -38,7 +37,9 @@ interface GitHub {
38
37
data class Contributor (val login : String , val contributions : Int )
39
38
data class Repo (val name : String )
40
39
41
- fun main (args : Array <String >) {
40
+ fun main (args : Array <String >) = runBlocking {
41
+ println (" Making GitHub API request" )
42
+
42
43
val retrofit = Retrofit .Builder ().apply {
43
44
baseUrl(" https://api.github.com" )
44
45
addConverterFactory(GsonConverterFactory .create())
@@ -47,19 +48,17 @@ fun main(args: Array<String>) {
47
48
48
49
val github = retrofit.create(GitHub ::class .java)
49
50
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 )
54
54
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: " )
57
57
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(" , " )
61
61
62
- println (otherRepos)
63
- }
62
+ println (otherRepos)
64
63
}
65
64
}
0 commit comments