提交 8cbb89c0 编写于 作者: A Aaron Patterson

subscriber does not need to be a block, but an object that responds to #call

上级 b2c8a5fd
......@@ -8,9 +8,9 @@ def initialize
@listeners_for = {}
end
def subscribe(pattern = nil, &block)
def subscribe(pattern = nil, block = Proc.new)
@listeners_for.clear
Subscriber.new(pattern, &block).tap do |s|
Subscriber.new(pattern, block).tap do |s|
@subscribers << s
end
end
......@@ -33,14 +33,14 @@ def wait
end
class Subscriber #:nodoc:
def initialize(pattern, &block)
def initialize(pattern, delegate)
@pattern = pattern
@block = block
@delegate = delegate
end
def publish(*args)
return unless subscribed_to?(args.first)
@block.call(*args)
@delegate.call(*args)
true
end
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册