jgraichen / restify

Restify is a experimental, parallel and pipelined Hypermedia API client
GNU Lesser General Public License v3.0
8 stars 2 forks source link

Add promise wait timeout #15

Closed jgraichen closed 6 years ago

jgraichen commented 6 years ago

This PR introduce a timeout capability to promises defaulting to 300 seconds. The timeout is required and cannot be zero.

franzliedke commented 6 years ago

Hmm... let's (ahem) sleep over this one for a bit. I just read too many bad things about Ruby's Timeout module:

Most importantly, this one: https://vaneyckt.io/posts/the_disaster_that_is_rubys_timeout_method/ (That has a nice example that could help us find out whether Timeout.timeout causes problems with Restify as well.)

This might be a helpful, more positive, resource: https://github.com/ankane/the-ultimate-guide-to-ruby-timeouts

jgraichen commented 6 years ago

Interesting. No article seems to mention Thread#handle_interrupt.

jgraichen commented 6 years ago

I've made a new implementation based on an high-res timer interval that is used to pass the remaining time to subsequent operations. Running code such as promise code blocks will not be interrupted.