Class: Polyphony::Throttler
Overview
Implements general-purpose throttling
Instance Method Summary collapse
-
#call ⇒ any
(also: #process)
Invokes the throttler with the given block.
-
#initialize(rate) ⇒ Throttler
constructor
Initializes a throttler instance with the given rate.
Constructor Details
Instance Method Details
#call ⇒ any Also known as: process
Invokes the throttler with the given block. The throttler will automatically introduce a delay to keep to the maximum specified rate. The throttler instance is passed to the given block.
20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/polyphony/core/throttler.rb', line 20 def call now = ::Process.clock_gettime(::Process::CLOCK_MONOTONIC) delta = @next_time - now Polyphony.backend_sleep(delta) if delta > 0 result = yield self while true @next_time += @min_dt break if @next_time > now end result end |