Skip to content
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

Cancel request #166

Open
jakob-o opened this issue Jun 1, 2017 · 3 comments
Open

Cancel request #166

jakob-o opened this issue Jun 1, 2017 · 3 comments

Comments

@jakob-o
Copy link
Contributor

jakob-o commented Jun 1, 2017

Hi,

would it be possible to cancel a request. My use case is a long polling client that upon shutdown should be able to cancel any currently active request without having to wait for the read timeout.

Regards

Jakob

@0crat
Copy link

0crat commented Jun 1, 2017

@yegor256 please, pay attention to this issue

@yegor256
Copy link
Member

yegor256 commented Jun 2, 2017

@jakob-o I would recommend to use @Timeable annotation from jcabi-aspects: http://aspects.jcabi.com/annotation-timeable.html

@jakob-o
Copy link
Contributor Author

jakob-o commented Jun 2, 2017

Hi @yegor256,

if I am not mistaken this is not different (and probably worse) than setting the timeout on the request itself. What I would like to do is to explicitly cancel a running request (e.g. by closing the underlying socket). E.g.

// Thread 1
// Long polling request in a loop
Request request = new JdkRequest("http://www.example.com")
		.timeout(1000, 30000): // Long read timeout for long polling request
// Blocks until a response is sent / the read timeout kicks in
request.fetch();

// Thread 2
// System shutdown
// Let's assume this is encapsulated in a shutdown method
request.cancel(); // Closes the socket

Regards

Jakob

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants