Colton Idle
02/23/2023, 7:08 PMkevin.cianfarini
02/23/2023, 7:13 PMCall
objects returned from Retrofit?Colton Idle
02/23/2023, 7:16 PMkevin.cianfarini
02/23/2023, 7:19 PMCall.execute
anywhere?Call.enqueue
?Colton Idle
02/23/2023, 7:20 PMkevin.cianfarini
02/23/2023, 7:20 PMCall
called executeSuspending
suspend fun <T> Call<T>.executeSuspending(): Response<T> = suspendCancellableCoroutine { cont ->
enqueue(object : Callback {
override fun onResponse(call: Call<T>, response: Response<T>) = cont.resume(response)
override fun onFailure(call: Call<T>, t: Throwable) = cont.resumeWithException(t)
}
cont.invokeOnCancellation { this@executeSuspending.cancel() }
}
Colton Idle
02/23/2023, 7:28 PMAre you certain you want to make the function on the service suspending?I guess not, I'm just used to the "modern" way of calling apiService in my newer projects, but I went back to this codebase and theres no way i can upgrade all of the old stuff. An extension on Call sounds pretty neat actually. idky i didn't think of that.
kevin.cianfarini
02/23/2023, 7:29 PMColton Idle
02/23/2023, 7:34 PMkevin.cianfarini
02/23/2023, 7:37 PMCall.enqueue
internally dispatches call events to a threadpool managed by OkHttp (I’m 99% sure of this, but not certain)/**
* Asynchronously send the request and notify {@code callback} of its response or if an error
* occurred talking to the server, creating the request, or processing the response.
*/
void enqueue(Callback<T> callback);
Colton Idle
02/23/2023, 7:37 PMkevin.cianfarini
02/23/2023, 7:39 PMefemoney
02/27/2023, 10:49 AMawait()
kevin.cianfarini
02/27/2023, 1:51 PMColton Idle
02/27/2023, 2:18 PMkevin.cianfarini
02/27/2023, 2:55 PM