Class: Rare::Throttler

Inherits:
Object
  • Object
show all
Defined in:
lib/rare/throttler.rb

Instance Method Summary collapse

Constructor Details

#initializeThrottler

Returns a new instance of Throttler.



5
6
7
# File 'lib/rare/throttler.rb', line 5

def initialize
  @mutex = Mutex.new
end

Instance Method Details

#throttle(rpm:, key: 'default') ⇒ Object



9
10
11
12
13
# File 'lib/rare/throttler.rb', line 9

def throttle(rpm:, key: 'default')
  sleep sleep_interval until allowed?(seconds(rpm), key)

  yield if block_given?
end