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