Loosing reference to local variables while debugging inside Coroutine scope

Viewed 85

I have the following piece of code:

fun fetchProductFirstFold(url: String) {
    viewModelScope.launch(Dispatchers.IO) {
        val result = HkApiServiceProvider.productPageApiClient.getProductPageVariantFirstFoldAsync(
          url
        ) //Returns a deferred

        try {
          val response = result.await() //await the response
          val obj = ProductListingData(JSONObject(response.string()).get("results") as JSONObject) 
          Log.i("SUCCESS", result.toString()) //Loosing reference here
        } catch (e: Exception) {
          Log.i("ERROR", e.toString())
        }

    }
  }

By the time I am at line where it prints success logs, I loose reference to variables above like obj and response while debugging. I tried to look for resolution online but to no avail. Is this normal behavior or am I doing something wrong here?

Issue Image

0 Answers
Related