Class: Debci::Drain::LifeCycle
- Inherits:
-
Object
- Object
- Debci::Drain::LifeCycle
- Defined in:
- lib/debci/drain.rb
Instance Method Summary collapse
- #expire! ⇒ Object
- #expired? ⇒ Boolean
-
#initialize(life_cycle = 10) ⇒ LifeCycle
constructor
A new instance of LifeCycle.
- #retain ⇒ Object
Constructor Details
#initialize(life_cycle = 10) ⇒ LifeCycle
Returns a new instance of LifeCycle.
9 10 11 12 13 14 |
# File 'lib/debci/drain.rb', line 9 def initialize(life_cycle = 10) @mutex = Mutex.new @timestamp = Time.now @life_cycle = life_cycle @expired = false end |
Instance Method Details
#expire! ⇒ Object
22 23 24 25 26 |
# File 'lib/debci/drain.rb', line 22 def expire! @mutex.synchronize do @expired = true end end |
#expired? ⇒ Boolean
28 29 30 31 32 |
# File 'lib/debci/drain.rb', line 28 def expired? @mutex.synchronize do @expired || (Time.now - @timestamp > @life_cycle) end end |
#retain ⇒ Object
16 17 18 19 20 |
# File 'lib/debci/drain.rb', line 16 def retain @mutex.synchronize do @timestamp = Time.now end end |