저는 Cramp 프레임 워크를 Redis gem 및 em-synchrony 및 WebSocket과 함께 사용하여 채팅 관련 웹 응용 프로그램을 빌드하고 몇 가지 문제가 있습니다.Em-synchrony 및 PubSub 문제가있는 Ruby Redis
class DrawingAction < Cramp::Action
use_fiber_pool
self.transport = :websocket
on_start :user_joined
on_data :message_received
on_finish :user_left
def user_joined
# Create pub/sub clients for the user who just joined
initialize_pub_sub
end
def initialize_pub_sub
@@redis_client ||= Redis.new(:driver => :synchrony)
@publisher ||= Redis.new(:driver => :synchrony)
@subscriber ||= Redis.new(:driver => :synchrony)
end
def handle_join(join_data)
room_name = join_data[:room_name]
@subscriber.subscribe(room_name) do |on|
on.message do |channel, message|
render message
end
end
puts "fetching history items"
history_items = history_for_room(room_name)
render "{ \"history\": true, \"time:\": #{Time.now.to_f}, \"data\": [#{history_items.join(',')}] }"
end
handle_join
내 쥐의 행동의 on_message
이벤트 핸들러, 경련은 동시성과 섬유를 지원하기 때문에 클라이언트가 채널에 가입 한 후, @의 subscriber.subscribe에서 호출되는 :
다음 코드를 고려 블록은 pubsub 채널에서 가져온 메시지를 받아들이고 프로세스의 다른 모든 요소를 차단하지는 않지만 (응용 프로그램이 차단되지 않음) 의미가있는 것처럼 비 차단으로 작동하지만 다음 줄로 이동하지 않습니다 (puts "fetching history items"
)이 문제를 해결하기 위해 할 수있는 일에 대한 힌트를 얻었습니까?