Class: FFWD::Channel
- Inherits:
-
Object
- Object
- FFWD::Channel
- Defined in:
- lib/ffwd/channel.rb
Defined Under Namespace
Classes: Sub
Instance Attribute Summary collapse
-
#subs ⇒ Object
readonly
Returns the value of attribute subs.
Instance Method Summary collapse
- #<<(item) ⇒ Object
-
#initialize(log, name) ⇒ Channel
constructor
A new instance of Channel.
- #subscribe(&block) ⇒ Object
- #unsubscribe(sub) ⇒ Object
Constructor Details
#initialize(log, name) ⇒ Channel
Returns a new instance of Channel.
36 37 38 39 40 |
# File 'lib/ffwd/channel.rb', line 36 def initialize log, name @log = log @name = name @subs = Set.new end |
Instance Attribute Details
#subs ⇒ Object (readonly)
Returns the value of attribute subs.
34 35 36 |
# File 'lib/ffwd/channel.rb', line 34 def subs @subs end |
Instance Method Details
#<<(item) ⇒ Object
42 43 44 45 46 47 48 49 50 |
# File 'lib/ffwd/channel.rb', line 42 def <<(item) @subs.each do |sub| begin sub.block.call item rescue => e @log.error "#{@name}: Subscription failed", e end end end |
#subscribe(&block) ⇒ Object
52 53 54 55 56 |
# File 'lib/ffwd/channel.rb', line 52 def subscribe(&block) s = Sub.new(self, block) @subs << s return s end |
#unsubscribe(sub) ⇒ Object
58 59 60 |
# File 'lib/ffwd/channel.rb', line 58 def unsubscribe sub @subs.delete sub end |