Sha256: 30046f1ed345a708d60ce4c6cb72aeb4d894240a07d2b3886ade2de086ee3d61

Contents?: true

Size: 533 Bytes

Versions: 20

Compression:

Stored size: 533 Bytes

Contents

# n秒間sleepしつつ、mainスレッドをm秒間隔で動かしたい時に使う
class ProconBypassMan::CycleSleep
  attr_accessor :cycle_interval, :execution_cycle

  def initialize(cycle_interval: , execution_cycle: )
    @cycle_interval = cycle_interval
    @execution_cycle = execution_cycle
    @counter = 0
  end

  def sleep_or_execute
    result = nil
    if @counter >= @execution_cycle
      @counter = 0
      result = yield
    else
      @counter += 1
    end
    sleep(@cycle_interval)
    return result
  end
end

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
procon_bypass_man-0.3.12 lib/procon_bypass_man/support/cycle_sleep.rb
procon_bypass_man-0.3.11 lib/procon_bypass_man/support/cycle_sleep.rb
procon_bypass_man-0.3.10 lib/procon_bypass_man/support/cycle_sleep.rb
procon_bypass_man-0.3.9 lib/procon_bypass_man/support/cycle_sleep.rb
procon_bypass_man-0.3.8.1 lib/procon_bypass_man/support/cycle_sleep.rb
procon_bypass_man-0.3.8 lib/procon_bypass_man/support/cycle_sleep.rb
procon_bypass_man-0.3.7 lib/procon_bypass_man/support/cycle_sleep.rb
procon_bypass_man-0.3.6 lib/procon_bypass_man/support/cycle_sleep.rb
procon_bypass_man-0.3.5 lib/procon_bypass_man/support/cycle_sleep.rb
procon_bypass_man-0.3.4 lib/procon_bypass_man/support/cycle_sleep.rb
procon_bypass_man-0.3.3.1 lib/procon_bypass_man/support/cycle_sleep.rb
procon_bypass_man-0.3.3 lib/procon_bypass_man/support/cycle_sleep.rb
procon_bypass_man-0.3.2 lib/procon_bypass_man/support/cycle_sleep.rb
procon_bypass_man-0.3.1 lib/procon_bypass_man/support/cycle_sleep.rb
procon_bypass_man-0.3.0 lib/procon_bypass_man/support/cycle_sleep.rb
procon_bypass_man-0.2.3 lib/procon_bypass_man/support/cycle_sleep.rb
procon_bypass_man-0.2.2 lib/procon_bypass_man/support/cycle_sleep.rb
procon_bypass_man-0.2.1 lib/procon_bypass_man/support/cycle_sleep.rb
procon_bypass_man-0.2.0 lib/procon_bypass_man/support/cycle_sleep.rb
procon_bypass_man-0.1.23 lib/procon_bypass_man/support/cycle_sleep.rb