Class: EventMachine::Channel
Relationships & Source Files | |
Inherits: | Object |
Defined in: | lib/em/channel.rb |
Overview
Provides a simple thread-safe way to transfer data between (typically) long running tasks in defer and event loop thread.
Class Method Summary
- .new ⇒ Channel constructor
Instance Method Summary
-
#<<(*items)
Alias for #push.
-
#num_subscribers
Return the number of current subscribers.
-
#pop(*a, &b)
Fetches one message from the channel.
-
#push(*items)
(also: #<<)
Add items to the channel, which are pushed out to all subscribers.
-
#subscribe(*a, &b) ⇒ Integer
Takes any arguments suitable for EM::Callback() and returns a subscriber id for use when unsubscribing.
-
#unsubscribe(name)
Removes subscriber from the list.
- #gen_id private Internal use only Internal use only
Constructor Details
.new ⇒ Channel
# File 'lib/em/channel.rb', line 15
def initialize @subs = {} @uid = 0 end
Instance Method Details
#<<(*items)
Alias for #push.
# File 'lib/em/channel.rb', line 50
alias << push
#gen_id (private)
This method is for internal use only.
[ GitHub ]
# File 'lib/em/channel.rb', line 65
def gen_id @uid += 1 end
#num_subscribers
Return the number of current subscribers.
# File 'lib/em/channel.rb', line 21
def num_subscribers return @subs.size end
#pop(*a, &b)
Fetches one message from the channel.
#push(*items) Also known as: #<<
Add items to the channel, which are pushed out to all subscribers.
#subscribe(*a, &b) ⇒ Integer
Takes any arguments suitable for EM::Callback() and returns a subscriber id for use when unsubscribing.
#unsubscribe(name)
Removes subscriber from the list.