I have a function which returns a List of Strings. This function requesting a response from the server. But firstly the function returns null, then a bit later returns a response with String. How to make it return the string from the beginning, avoid "empty response"?
var array = listOf<String>()
private fun getNetworkResponse(): List<String> {
scope.launch {
val list = api.getVideo().data
val reply = list?.map { it?.url }
array = reply as List<String>
Log.d(MY_TAG, "array 1 $array ")
}
Log.d(MY_TAG, "array 2 $array ")
return array
}
So above function first return empty array, and late with response:
Log array 2 []
Log array 1 [https://..]