Ruby Fibers and faye
-
05-12-2019 - |
Question
I have simple script with EventMachine, Fibers and 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 comes first, event_2 next to it (very small interval)
When i run it and event's fired. I always have this output:
Event 1 start
Event 2 start
Event 2 finish
Thats all.
Where is Event 1 finish?
What i'm doing wrong?
UPD: If i remove asynchrones removing require 'redis/connection/synchrony'
all works great. But i need this asynchrones.
ruby-1.9.2-p290 [ x86_64 ]
Solution
The answer was to use Synchrony ConnectionPool.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow