Class: Debci::Drain::LifeCycle

Inherits:
Object
  • Object
show all
Defined in:
lib/debci/drain.rb

Instance Method Summary collapse

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

Returns:

  • (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

#retainObject



16
17
18
19
20
# File 'lib/debci/drain.rb', line 16

def retain
  @mutex.synchronize do
    @timestamp = Time.now
  end
end