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.



39
40
41
42
# File 'lib/message_bus/backends/memory.rb', line 39

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

Instance Attribute Details

#backlogObject

Returns the value of attribute backlog.



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

def backlog
  @backlog
end

#ttlObject

Returns the value of attribute ttl.



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

def ttl
  @ttl
end

Instance Method Details

#expired?Boolean

Returns:

  • (Boolean)


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

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