title: Kotlin coroutines block main thread in Android
body: <p>I am new in Kotlin and coroutines. I have a <code>fun</code> in my activity and inside it, check <code>User</code> username and password and if its true, return <code>Users</code> object.<br>
  every thing is Ok. but when I press button, my activity blocked and wait for response of <code>Users</code> login.<br>
  I use this fun: </p>
  
  <pre><code>private fun checkLogin() : Boolean {           
          runBlocking {
              coroutineScope {
                  launch {
                      user = viewModel.getUserAsync(login_username.text.toString(), login_password.text.toString()).await()
                  }
              }
              if(user == null){
                  return@runBlocking false
              }
              return@runBlocking true
          }
          return false
      }  
  </code></pre>
  
  <p>It's my ViewModel :   </p>
  
  <pre><code>class LoginViewModel(app: Application) : AndroidViewModel(app) {
      val context: Context = app.applicationContext
      private val userService = UsersService(context)
  
      fun getUserAsync(username: String, password: String) = GlobalScope.async {
          userService.checkLogin(username, password)
      }
  }
  </code></pre>
  
  <p>UsersService:  </p>
  
  <pre><code>class UsersService(ctx: Context) : IUsersService {
          private val db: Database = getDatabase(ctx)
          private val api = WebApiService.create()
          override fun insertUser(user: Users): Long {
              return db.usersDao().insertUser(user)
          }
  
          override suspend fun checkLogin(username: String, pass: String): Users? {
              return api.checkLogin(username, pass)
          }
      }
  
      interface IUsersService {
          fun insertUser(user: Users) : Long
          suspend fun checkLogin(username: String, pass: String): Users?
      }
  </code></pre>
  
  <p>And it is my apiInterface:</p>
  
  <pre><code>interface WebApiService {
  
      @GET("users/login")
      suspend fun checkLogin(@Query("username") username: String,
                     @Query("password")password: String) : Users
  </code></pre>
  
  <p>How can I resolve issue of blocking my activity when waiting for retrieve data from server? </p>