Simple use of EM::Synchrony#sync causes 'root fiber' FiberError — my fault?

余生长醉 提交于 2019-12-03 20:37:02

I think your code can work if you find the correct version of em-hiredis it is trying to monkey patch, that is one problem with loose dependencies.

Here is a fully working code but based on the master branch of em-synchrony:

Gemfile:

source :rubygems

gem 'em-synchrony', :git => "git://github.com/igrigorik/em-synchrony.git"
gem 'em-hiredis', '~> 0.1.0'

test.rb:

require 'rubygems'
require 'bundler/setup'

require 'em-synchrony'
require 'em-synchrony/em-hiredis'

EventMachine.synchrony do
  redis = EM::Hiredis.connect

  redis.set('foo', 'bar')
  puts redis.get('foo')

  EM.stop
end

and then run it with:

$ bundle
$ ruby test.rb

Monkey patching is an inherently flawed way of patching gems unless you ensure the exact version of the gem you patched is used which is something em-synchrony should enforce or at least detect.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!