您的实际代码具有:
Hash(String, Array({String, String -> })).new
这个元组与
{(String, String ->)}
所以你需要parens来消除歧义
Hash(String, Array({String, (String -> )})).new
您的实际代码也存在 Void 到处出现的问题,我不知道为什么,但一些演员可以解决它。这是使其工作的完整差异
diff --git a/src/untangle/aggregator.cr b/src/untangle/aggregator.cr
index 8c49681..7553eb2 100644
--- a/src/untangle/aggregator.cr
+++ b/src/untangle/aggregator.cr
@@ -3,7 +3,7 @@ class Aggregator
@@subscribers_all = Array(String, String ->).new
@@responders = Hash(String, (String ->)).new
#@@reroutes = {} of String => Proc(String)
- @@reroutes = Hash(String, Array({String, String -> })).new {|h, k| h[k] = Array({String, String -> }).new }
+ @@reroutes = Hash(String, Array({String, (String -> )})).new {|h, k| h[k] = Array({String, (String -> )}).new }
def self.subscribe (message_type, &callback : String ->)
@@subscribers[message_type] << callback
@@ -35,11 +35,11 @@ class Aggregator
spawn do
message_type = ch.receive
data = ch.receive
- callback.call(message_type, data)
+ callback.call(message_type, data as String)
end
ch.send(message_type)
- ch.send(data)
+ ch.send(data as String)
end
@@subscribers[message_type].each do |callback|
@@ -48,14 +48,14 @@ class Aggregator
spawn do
callback.call(ch.receive)
end
- ch.send(data)
+ ch.send(data as String)
end
@@reroutes[message_type].each do |tuple| #|to_type, callback|
# puts "!!!!!!!!!!!!!!!!!!!"
# pp tuple
# puts "!!!!!!!!!!!!!!!!!!!"
- Aggregator.publish(tuple[0], tuple[1].call(data))
+ Aggregator.publish(tuple[0], tuple[1].call(data as String))
end
end
def self.request(message_type, arguments)
如果您计划在 Crystal 社区中采用您的库,还请阅读http://crystal-lang.org/docs/conventions/coding_style.html 。