3

我有 EventMachine、Fibers 和 faye 的简单脚本

require "faye"
require "em-synchrony"
require "hiredis"
require 'redis'
require 'redis/connection/synchrony'

faye = Faye::Client.new 'http://localhost:9292/faye'
redis = Redis.new

EM.synchrony do

  faye.subscribe('/event_1') do |message|
    Fiber.new do
      puts "Event 1 start"
      user_id = redis.hget 'myhash', message.client_id
      puts "Event 1 finish"
    end.resume
  end 

  faye.subscribe('/event_2') do |message|
    Fiber.new do
      puts "Event 2 start"
      user_id = redis.hget 'myhash', message.client_id
      puts "Event 2 finish"
     end.resume
  end # subscribe

end #EM.synchrony

event_1 首先出现,event_2 在它旁边(非常小
的间隔)当我运行它并触发事件时。我总是有这个输出:

Event 1 start
Event 2 start
Event 2 finish

就这样。
事件 1 结束在哪里?
我做错了什么?

UPD:如果我删除异步删除require 'redis/connection/synchrony'所有工作都很好。但我需要这个异步。

ruby-1.9.2-p290 [x86_64]

4

1 回答 1

1

The answer was to use Synchrony ConnectionPool.

于 2012-06-26T13:07:21.263 回答