改型Call.enqueue()按照创建的顺序发送请求?

想象一下这种情况:

我使用Call.enqueue()方法启动 requestA ,然后在完成 requestA 之前,我同时启动 requestB requestA 的端点。当我使用Call.enqueue()方法时, requestB 将在 requestA 之后执行吗?还是enqueue()方法仅用于异步执行请求?

我在docs以及此处的StackOverflow上搜索了这些信息,但所有信息都只是关于此特定方法的肤浅信息。

这是我的代码-相同的代码用于两个请求:

* {
  margin: 0;
  padding: 0
}

html { height: 100% }

html,body,section {
  display: flex;
  flex-grow: 1
}

body {
  scroll-snap-type: x mandatory;
  scroll-snap-points-x: repeat(100%);
  overflow-x: auto;
}

section {
  display: grid;
  place-items: center;
  flex: 1 0 100%;
  scroll-snap-align: center
}

section:nth-of-type(1) { background: orange }
section:nth-of-type(2) { background: limeGreen }
section:nth-of-type(3) { background: royalBlue }

h2 { color: white }
xj0605 回答:改型Call.enqueue()按照创建的顺序发送请求?

我这么认为, 否则,如果您实现自己的连接客户端。 通过OkHttpClient的源代码,有一个调度程序类,保存所有入队API,并使用队列保存相关任务

synchronized void enqueue(AsyncCall call) {
    if (runningAsyncCalls.size() < maxRequests && runningCallsForHost(call) < maxRequestsPerHost) {
      runningAsyncCalls.add(call);
      executorService().execute(call);
    } else {
      readyAsyncCalls.add(call);
    }
}
本文链接:https://www.f2er.com/3159174.html

大家都在问