Skip to content

Instantly share code, notes, and snippets.

sealed class Result<T>
class SuccessfulResult<T>(val responseBody: T): Result<T>()
class UnsuccessfulResult<T>(val response: Response<T>?): Result<T>()
class ExceptionalResult<T>(val throwable: Throwable?): Result<T>()
suspend fun <T : Any> Call<T>.awaitResult(): Result<T> {
return suspendCancellableCoroutine { continuation ->
continuation.invokeOnCancellation {
cancel()
}