module THTP::Server::PubSub
A truly trivial pub/sub implementation for instrumentation. Note, NOT threadsafe; make sure all subscribers are added before publishing anything.
Public Instance Methods
subscribe(subscriber)
click to toggle source
Add listeners to be run in the order of subscription
# File lib/thtp/server/pub_sub.rb, line 7 def subscribe(subscriber) subscribers << subscriber end
Private Instance Methods
publish(event, *args)
click to toggle source
If a subscriber raises an exception, any future ones won't run: this is not considered a bug. Don't raise.
# File lib/thtp/server/pub_sub.rb, line 15 def publish(event, *args) # freeze to prevent any subscriber changes after usage subscribers.freeze.each { |l| l.send(event, *args) if l.respond_to?(event) } end
subscribers()
click to toggle source
# File lib/thtp/server/pub_sub.rb, line 20 def subscribers @subscribers ||= [] end