Является ли модернизированный `Call :: execute` поточно-ориентированным? - PullRequest
0 голосов
/ 27 февраля 2019

Так что мне действительно не нравится аспект обратного вызова Call::enqueue.

. Я бы предпочел заключить вызов на Call::execute в Future.

Какбезопасно делать что-то вроде

/**An auxiliary retrofit controller to facilitate communication with the server during testing.*/
object Server : CoroutineScope{

    private val job = Job()
    override val coroutineContext: CoroutineContext
        get() = job + Dispatchers.IO

    const val URL = ...

    private val retrofit = Retrofit.Builder()
            .baseUrl(URL)
            .addConverterFactory(GsonConverterFactory.create())
            .build()
            .create(DebugServerAPI::class.java)

    /**Sends the [somethingRequest] to the server.
     * @return a [Deferred] holding the server [Response]*/
    fun trySomething(jwt:String,somethingRequest:JsonObject):Deferred<Response<JsonObject>>{
        return async { retrofit.something(jwt,somethingRequest).execute() }
    }
}

?

...