Module: Semian::Instrumentable

Included in:
Semian
Defined in:
lib/semian/instrumentable.rb

Constant Summary collapse

SUBSCRIBERS =
Concurrent::Map.new

Instance Method Summary collapse

Instance Method Details

#notify(*args) ⇒ Object

Args:

event (string)
resource (Object)
scope (string)
adapter (string)
payload (optional)


28
29
30
# File 'lib/semian/instrumentable.rb', line 28

def notify(*args)
  SUBSCRIBERS.values.each { |subscriber| subscriber.call(*args) }
end

#subscribe(name = rand, &block) ⇒ Object



9
10
11
12
# File 'lib/semian/instrumentable.rb', line 9

def subscribe(name = rand, &block)
  SUBSCRIBERS[name] = block
  name
end

#subscribersObject



18
19
20
# File 'lib/semian/instrumentable.rb', line 18

def subscribers
  SUBSCRIBERS
end

#unsubscribe(name) ⇒ Object



14
15
16
# File 'lib/semian/instrumentable.rb', line 14

def unsubscribe(name)
  SUBSCRIBERS.delete(name)
end