Module: CitrusRpc::Utils::EventEmitter
- Included in:
- RpcClient::MailStation, RpcClient::WsMailBox, RpcServer::Gateway, RpcServer::Server, RpcServer::WsAcceptor
- Defined in:
- lib/citrus-rpc/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
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
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
25 26 27 28 |
# File 'lib/citrus-rpc/util/utils.rb', line 25 def once event, &block @once_blocks ||= {} @once_blocks[event] = block end |