Class: ProconBypassMan::CycleSleep
- Inherits:
-
Object
- Object
- ProconBypassMan::CycleSleep
- Defined in:
- lib/procon_bypass_man/support/cycle_sleep.rb
Overview
n秒間sleepしつつ、mainスレッドをm秒間隔で動かしたい時に使う
Instance Attribute Summary collapse
-
#cycle_interval ⇒ Object
Returns the value of attribute cycle_interval.
-
#execution_cycle ⇒ Object
Returns the value of attribute execution_cycle.
Instance Method Summary collapse
-
#initialize(cycle_interval:, execution_cycle:) ⇒ CycleSleep
constructor
A new instance of CycleSleep.
- #sleep_or_execute ⇒ Object
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_interval ⇒ Object
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_cycle ⇒ Object
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_execute ⇒ Object
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 |