Module: Citrus::Utils::EventEmitter
- Included in:
- Application, Common::Service::SessionService::FrontendSession, Common::Service::SessionService::Session, Connectors::WsConnector, Connectors::WsSocket
- Defined in:
- lib/citrus/util/utils.rb
Overview
EventEmitter
Instance Method Summary collapse
-
#emit(*args) ⇒ Object
Emit event.
-
#on(event, &block) ⇒ Object
Register event.
-
#once(event, &block) ⇒ Object
Register event once.
Instance Method Details
#emit(*args) ⇒ Object
Emit event
38 39 40 41 42 43 44 45 46 |
# File 'lib/citrus/util/utils.rb', line 38 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
24 25 26 27 |
# File 'lib/citrus/util/utils.rb', line 24 def on event, &block @on_blocks ||= {} @on_blocks[event] = block end |
#once(event, &block) ⇒ Object
Register event once
32 33 34 35 |
# File 'lib/citrus/util/utils.rb', line 32 def once event, &block @once_blocks ||= {} @once_blocks[event] = block end |