Module: CitrusRpc::Utils::EventEmitter

Overview

EventEmitter

Instance Method Summary collapse

Instance Method Details

#emit(*args) ⇒ Object

Emit event



31
32
33
34
35
36
37
38
39
# File 'lib/citrus-rpc/util/utils.rb', line 31

def emit *args
  event = args.shift
  if @once_blocks && block = @once_blocks[event]
    @once_blocks.delete event
  elsif !@on_blocks || !block = @on_blocks[event]
    return
  end
  block.call *args
end

#on(event, &block) ⇒ Object

Register event

Parameters:

  • event (String)


17
18
19
20
# File 'lib/citrus-rpc/util/utils.rb', line 17

def on event, &block
  @on_blocks ||= {}
  @on_blocks[event] = block
end

#once(event, &block) ⇒ Object

Register event once

Parameters:

  • event (String)


25
26
27
28
# File 'lib/citrus-rpc/util/utils.rb', line 25

def once event, &block
  @once_blocks ||= {}
  @once_blocks[event] = block
end