我正在尝试创建一个将返回有关EventMachine服务器的统计信息的Sinatra服务器。也就是说,我运行: EventMachine.run do
server = EventMachine.start_server 'localhost', 3333, MyApp
dispatch = Rack::Builder.app do
map '/' do
我有问题了解使用带有eventmachine的光纤模型调用外部API时发生了什么。我有这样的代码在西纳特拉: get '/' do
conn = Faraday.new 'http://slow-api-call' do |con|
con.adapter :em_http
end
resp = conn.get
resp.on_complete
调用周期性定时器,当块内发生错误时,更改此周期性定时器延迟。我可以使用定期计时器还是最好的方法是add_timer? 嗨,我想这样做: EventMachine.run
EventMachine.add_periodic_timer 1
//read from a input
//if error set timer to 20s
//if ok set t
在ruby标准库中,popen返回一个有pid方法的对象, 在eventmachine中,popen返回一个不包含进程id信息的Connection对象。 演示这里代码: require 'eventmachine'
def work
s = EM.popen('ls')
puts s.pid # how to get new process's pid?
end
E