Class: MessageBus::Backends::Memory::Client::Channel

Inherits:
Object
  • Object
show all
Defined in:
lib/message_bus/backends/memory.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(ttl:) ⇒ Channel

Returns a new instance of Channel.



37
38
39
40
# File 'lib/message_bus/backends/memory.rb', line 37

def initialize(ttl:)
  @backlog = []
  @ttl = ttl
end

Instance Attribute Details

#backlogObject

Returns the value of attribute backlog.



35
36
37
# File 'lib/message_bus/backends/memory.rb', line 35

def backlog
  @backlog
end

#ttlObject

Returns the value of attribute ttl.



35
36
37
# File 'lib/message_bus/backends/memory.rb', line 35

def ttl
  @ttl
end

Instance Method Details

#expired?Boolean

Returns:

  • (Boolean)


42
43
44
45
46
47
48
49
50
51
52
# File 'lib/message_bus/backends/memory.rb', line 42

def expired?
  last_publication_time = nil
  backlog.each do |_id, _value, published_at|
    if !last_publication_time || published_at > last_publication_time
      last_publication_time = published_at
    end
  end
  return true unless last_publication_time

  last_publication_time < Time.now - ttl
end