Class: FFWD::Channel

Inherits:
Object
  • Object
show all
Defined in:
lib/ffwd/channel.rb

Defined Under Namespace

Classes: Sub

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#subsObject (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