Add mock queue implementation

This commit is contained in:
Tim Kächele 2024-02-10 11:18:06 +01:00
parent b9ea7cca30
commit 19afa23021

View File

@ -0,0 +1,32 @@
class MockQueue
attr_reader :messages
def initialize
@messages = []
@subscription_id = 0
@subscriptions = {}
end
def subscribe(&block)
@subscription_id += 1
@subscriptions[@subscription_id] = block
@subscription_id
end
def push(message)
@messages.push(message)
@subscriptions.values.each do |callback|
callback.call(message)
end
message
end
def clear_messages!
@messages = []
end
def unsubscribe(subscription_id)
@subscriptions.delete(subscription_id)
nil
end
end