1
0
mirror of https://github.com/square/okhttp.git synced 2025-12-03 18:31:17 +03:00

Make all TaskRunner tasks cancelable

This probably should have been the case all along. Unfortunately,
ExecutorService Runnables are not cancelable by default, and that's
where we started.

After implementing all of TaskRunner it looks like where we're
cancelable and where we aren't is totally arbitrary. Making everything
cancelable simplifies the implementation and model.

The last remaining non-cancelable tasks:
 * awaitIdle() which we use in our tests only.
 * MockWebServer, where canceling would leak sockets
This commit is contained in:
Jesse Wilson
2019-10-06 17:38:37 -04:00
parent 4096e375c0
commit 0a691dcadb
8 changed files with 58 additions and 71 deletions

View File

@@ -389,7 +389,7 @@ class MockWebServer : ExternalResource(), Closeable {
portField = serverSocket!!.localPort
taskRunner.newQueue().execute("MockWebServer $portField") {
taskRunner.newQueue().execute("MockWebServer $portField", cancelable = false) {
try {
logger.info("${this@MockWebServer} starting to accept connections")
acceptConnections()
@@ -464,7 +464,7 @@ class MockWebServer : ExternalResource(), Closeable {
}
private fun serveConnection(raw: Socket) {
taskRunner.newQueue().execute("MockWebServer ${raw.remoteSocketAddress}") {
taskRunner.newQueue().execute("MockWebServer ${raw.remoteSocketAddress}", cancelable = false) {
try {
SocketHandler(raw).handle()
} catch (e: IOException) {