New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make Rest.Response Closeable #237
Comments
I like your idea of implementing Closeable. I'll investigate this later today and get back to you. |
Rest.Response now implements Closeable. But in your example, there was no resource leak FAIK. The reason is that @Test
fun testAutoclose() {
val hangingResponse = api.get("/category")
FX.runAndWait {
Assert.assertEquals(1, Rest.ongoingRequests.size)
}
hangingResponse.use {
}
FX.runAndWait {
Assert.assertEquals(0, Rest.ongoingRequests.size)
}
} The reson the asserts are run inside |
TornadoFX 1.6.1 is released with this improvement :) |
Looks good, thanks! Not sure what you mean by |
Great! That might only have been true for the HttpURLConnection version, I didn't check the HttpClient version :) |
The following client code triggers a resource leak when handling a non-2xx response and requires a try-finally to work correctly.
Having Response inherit from Closeable would allow
Closeable.use
extension function to correctly close the response object.Alternatively,
post()
could accept a lambda receiving a response object, but that place is already taken by a request processor.The text was updated successfully, but these errors were encountered: