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

Interface improvement #32

Open
rodrigomonteirof opened this issue Apr 26, 2018 · 1 comment
Open

Interface improvement #32

rodrigomonteirof opened this issue Apr 26, 2018 · 1 comment

Comments

@rodrigomonteirof
Copy link

rodrigomonteirof commented Apr 26, 2018

I've been wondering... Why not allow receive some configurations on initialize method?

Today:

def with_ratelimit(&block)                                                                                               
  ratelimit = Ratelimit.new("whatsapp", { bucket_interval: BUCKET_INTERVAL })                                            
                                                                                                                               
  ratelimit.exec_within_threshold('send_message',  threshold: THRESHOLD, interval: INTERVAL) do                          
    ratelimit.add('send_message')                                                                                        
    yield                                                                                                                
  end                                                                                                                    
end 

Desire:

def with_ratelimit(&block)
  opts = { bucket_interval: BUCKET_INTERVAL, threshold: THRESHOLD, interval: INTERVAL}

  Ratelimit.new("whatsapp::send_message", opts).exec_within_threshold do
   # doesnt need to use add method anymore                                                                             
    yield                                                                                                                
  end                                                                                                                    
end

I can implement this modification if you agree, what do you think?

@ejfinneran
Copy link
Owner

Sorry for the delay. This looks good to me. My only concern is changing the bucket interval between calls to the same key might yield strange results. We'd just need to test for that.

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

No branches or pull requests

2 participants