toland / patron

Ruby HTTP client based on libcurl
http://toland.github.com/patron/
MIT License
541 stars 74 forks source link

Add Ruby progress callback + customise our GIL unblock function #151

Closed julik closed 6 years ago

julik commented 6 years ago

We should provide some ability for users to re-acquire the GIL and call Ruby callback blocks. We will start with a progress callback which can be used for progress bars and speed computation. We also need to alter the way we unblock the thread so that we correctly handle signals.

This adds the following API:

sess.progress_callback = ->(download_total, download_now, upload_total, upload_now) {
  progress_bar.update(download_total) # ...or other interesting actions
}

The GIL will only be reacquired if this is configured on the Session/Request objects, otherwise we proceed through the same fast path as before with the GIL unlocked.

Closes #150 and paves the way for making #139 possible

julik commented 6 years ago

150 and should open the door for #139 (because we need to manage the GIL very carefully for these). Also is going to allow programmatic abort from a callback proc, which can be a neat feature to have.

julik commented 6 years ago

@marshall-lee since you stumbled upon this anyway - have you got an idea what I should use instead of rb_thread_call_with_gvl when we only have rb_thread_blocking_region available (for pre-2.2 Rubies). I've been looking around but it seems all the docs online now only mention rb_thread_blocking_region being removed.

julik commented 6 years ago

@toland ?

toland commented 6 years ago

LGTM.