lib/polyphony/core/global_api.rb
# call-seq:
#   throttled_loop(rate) { ... }
#   throttled_loop(interval: value) { ... }
#   throttled_loop(rate: value) { ... }
#   throttled_loop(rate, count: value) { ... }
#
# Starts a throttled loop with the given rate. If `count:` is given, the
# loop is run for the given number of times. Otherwise, the loop is
# infinite. The loop rate (times per second) can be given as the rate
# parameter. The throttling can also be controlled by providing an
# `interval:` or `rate:` named parameter.
#
# @param rate [Number, nil] loop rate (times per second)
# @param rate: [Number] loop rate (times per second)
# @param interval: [Number] loop interval in seconds
# @param count: [Number, nil] number of iterations (nil for infinite)
# @param &block [Proc] code to run
# @return [void]


Starts a throttled loop with the given rate. If `count:` is given, the
loop is run for the given number of times. Otherwise, the loop is
infinite. The loop rate (times per second) can be given as the rate
parameter. The throttling can also be controlled by providing an
`interval:` or `rate:` named parameter.
Starts a throttled loop with the given rate . If ` count : ` is given the loop is run for the given number of times . Otherwise the loop is infinite . The loop rate ( times per second ) can be given as the rate parameter . The throttling can also be controlled by providing an ` interval : ` or ` rate : ` named parameter .
def throttled_loop(rate = nil, **opts, &block)
      throttler = Polyphony::Throttler.new(rate || opts)
      if opts[:count]
        opts[:count].times { |_i| throttler.(&block) }
      else
        while true
          throttler.(&block)
        end
      end
    rescue LocalJumpError, StopIteration
    end
def throttled_loop ( rate = nil , ** opts , & block ) throttler = Polyphony :: Throttler . new ( rate || opts ) if opts [ :count ] opts [ :count ] . times { | _i | throttler . ( & block ) } else while true throttler . ( & block ) end end rescue LocalJumpError , StopIteration end
call-seq:
throttled_loop(rate) { ... }
throttled_loop(interval: value) { ... }
throttled_loop(rate: value) { ... }
throttled_loop(rate, count: value) { ... }
call - seq : throttled_loop ( rate ) { ... } throttled_loop ( interval : value ) { ... } throttled_loop ( rate : value ) { ... } throttled_loop ( rate count : value ) { ... }
# break called or StopIteration raised
None
void
rate
loop rate (times per second)
loop rate ( times per second )
opts
<not_specific>
block
<not_specific>
rate:
<not_specific>
loop rate (times per second)
loop rate ( times per second )
interval:
<not_specific>
loop interval in seconds
loop interval in seconds
count:
<not_specific>
number of iterations (nil for infinite)
number of iterations ( nil for infinite )
&block
<not_specific>
code to run
code to run