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

Allow bypassing futuroscope entirely #109

Merged
merged 7 commits into from
Dec 21, 2016
Merged

Allow bypassing futuroscope entirely #109

merged 7 commits into from
Dec 21, 2016

Conversation

ivoanjo
Copy link
Contributor

@ivoanjo ivoanjo commented Dec 20, 2016

As discussed in #102 there are cases where we don't really want the async behavior provided by futuroscope.

In @Talkdesk's case, we're using hyperclient with the manticore gem that already has its own worker thread pool.

While the proposed NoPool approach kind-of works, that approach is global. This means that you chose once for your entire system whether you have a pool or not, and that choice impacts all hyperclient instances (even communicating with different systems) and futuroscope users (unless they allow you to override the pool, which for instance hyperclient doesn't).

Since that is rather heavy-handed, instead this PR adds an async_options to the EntryPoint, which allows hyperclient uses to per-instance specify if they want requests to be asynchronous or not. By default, the previous async behavior is followed, but this can be changed easily.

In the future I hope to also expand the async_options so you can specify a specific pool, so that you can have different pools for different hyperclient instances.

@@ -1,8 +1,9 @@
### 0.8.2 (Next)

This version is no longer tested with Ruby < 2.2.
# This version is no longer tested with Ruby < 2.2.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know this is just for Danger, but maybe make it 4 ####.


```ruby
api = Hyperclient.new('https://grape-with-roar.herokuapp.com/api') do |client|
client.async_options = {enabled: false}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor: make it Ruby pretty, add a space after { and before }.

@@ -39,6 +39,7 @@ class EntryPoint < Link
def initialize(url, &_block)
@link = { 'href' => url }
@entry_point = self
@async_options = {enabled: true}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rubocop -a will fix this too

response = Futuroscope::Future.new do
@entry_point.connection.run_request(method, _url, body, nil)
end
do_async = @entry_point.async_options[:enabled]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor, but this isn't used in more than one place, so I would just do if @entry_point.async ....

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've updated this to do if @entry_point.options[:async] directly. Would you prefer I add an explicit async getter allowing this code to do if @entry_point.async instead?

@dblock
Copy link
Collaborator

dblock commented Dec 20, 2016

First, thank you, this is great. I feel like this should just be options and there should be options[:async], this way it would be more future-proof?

@ivoanjo
Copy link
Contributor Author

ivoanjo commented Dec 21, 2016

Thanks for the feedback! I'll make the changes you suggested asap :)

Ivo Anjo added 7 commits December 21, 2016 15:43
This addition will be used in the Link to control if requests are done
using futuroscope in a background thread or not.
This allows requests to bypass futuroscope entirely, rather than
needing to rely on setting the global pool to NoPool.
Tweak changelog formatting to avoid warnings.
@ivoanjo
Copy link
Contributor Author

ivoanjo commented Dec 21, 2016

@dblock care to re-review? 😄

@dblock
Copy link
Collaborator

dblock commented Dec 21, 2016

Merging this, thanks! Made minor comments if you want to address them in a future PR feel free.

@dblock dblock merged commit 4705594 into codegram:master Dec 21, 2016

```ruby
api = Hyperclient.new('https://grape-with-roar.herokuapp.com/api') do |client|
client.options.merge!(async: false)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to change this, but in Ruby this is an antipattern. All you're doing is setting async, so client.options[:async] = false is a much clearer operation than merge.

# Public: Read options.
#
# Returns a Hash.
attr_reader :options
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These should be combined as attr_accessor, no?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I separated them to have documentation on both, but it may not be useful enough to warrant that distinction.

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

Successfully merging this pull request may close these issues.

2 participants