Q:

use withContext once on twice. Both work, or

I must execute http request (Retrofit 2) in background thread.
approach #1:
 suspend fun getTraidersList(): TransportResponse = withContext(Dispatchers.IO) {
            val traderMonitorRestClient = RestClientFactory.createRestClient(TraderMonitorRestClient::class.java)
            executeOperation { traderMonitorRestClient.getTraidersList() }
        }

  suspend private fun executeOperation(transportOperation: suspend () -> Response<*>): TransportResponse {
            try {
                val response: Response<*> = transportOperation()
                return onResponse(response)
            } catch (e: Throwable) {
                return onNetworkFailure(e)
            }
        }
}

As you can see the method getTraidersList() is start in background thread by withContext(Dispatchers.IO). But in method executeOperation I'm not using withContext(Dispatchers.IO).
Nice. It's work fine.
approach #2:
Using withContext(Dispatchers.IO)  also in method  executeOperation
suspend fun getTraidersList(): TransportResponse = withContext(Dispatchers.IO) {
            val traderMonitorRestClient = RestClientFactory.createRestClient(TraderMonitorRestClient::class.java)
            executeOperation { traderMonitorRestClient.getTraidersList() }
}

 suspend private fun executeOperation(transportOperation: suspend () -> Response<*>): TransportResponse = withContext(Dispatchers.IO) {
            try {
                val response: Response<*> = transportOperation()
                onResponse(response)
            } catch (e: Throwable) {
                onNetworkFailure(e)
            }
}

Both approaches work.
But which approach is correct? Maybe, both approaches are correct?

A:

If you are going to reuse the executeOperation method anywhere else it's okay to put into another thread but for now, in your case, it's not needed.
This can also work in case you want to reuse the executeOperation method.
suspend fun getTraidersList(): TransportResponse {
            val traderMonitorRestClient = RestClientFactory.createRestClient(TraderMonitorRestClient::class.java)
            executeOperation { traderMonitorRestClient.getTraidersList() }
}

 suspend private fun executeOperation(transportOperation: suspend () -> Response<*>): TransportResponse = withContext(Dispatchers.IO) {
            try {
                val response: Response<*> = transportOperation()
                onResponse(response)
            } catch (e: Throwable) {
                onNetworkFailure(e)
            }
}

