请问有人能解释一下为什么 Redis (redis-rb) 同步驱动在 EM.synchrony 块内直接工作,但不在 EM:Connection 内工作吗?
考虑以下示例:
EM.synchrony do
redis = Redis.new(:path => "/usr/local/var/redis.sock")
id = redis.incr "local:id_counter"
puts id
EM.start_server('0.0.0.0', 9999) do |c|
def c.receive_data(data)
redis = Redis.new(:path => "/usr/local/var/redis.sock")
puts redis.incr "local:id_counter"
end
end
end
我正在获取
can't yield from root fiber (FiberError)
当在receive_data
中使用时。从阅读EventMachine和em-synchrony的源代码中,我无法弄清楚它们之间的区别。
谢谢!
PS:显然的解决方法是将redis代码包装在EventMachine::Synchrony.next_tick中,如问题#59所示,但考虑到EM.synchrony,我希望已经在Fiber中包装了调用...
PPS:同样适用于使用EM :: Synchrony :: Iterator