Class: ProconBypassMan::CycleSleep

Inherits:
Object
  • Object
show all
Defined in:
lib/procon_bypass_man/support/cycle_sleep.rb

Overview

n秒間sleepしつつ、mainスレッドをm秒間隔で動かしたい時に使う

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(cycle_interval:, execution_cycle:) ⇒ CycleSleep

Returns a new instance of CycleSleep.



5
6
7
8
9
# File 'lib/procon_bypass_man/support/cycle_sleep.rb', line 5

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

Instance Attribute Details

#cycle_intervalObject

Returns the value of attribute cycle_interval.



3
4
5
# File 'lib/procon_bypass_man/support/cycle_sleep.rb', line 3

def cycle_interval
  @cycle_interval
end

#execution_cycleObject

Returns the value of attribute execution_cycle.



3
4
5
# File 'lib/procon_bypass_man/support/cycle_sleep.rb', line 3

def execution_cycle
  @execution_cycle
end

Instance Method Details

#sleep_or_executeObject



11
12
13
14
15
16
17
18
19
20
21
# File 'lib/procon_bypass_man/support/cycle_sleep.rb', line 11

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