From 5c5372c888cb32795cd8fd9f3afffe79fd652d39 Mon Sep 17 00:00:00 2001 From: Martin Edenhofer Date: Sat, 4 Aug 2012 11:38:18 +0200 Subject: [PATCH] Delay client thread if user thread is the first. --- lib/web_socket.rb | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/lib/web_socket.rb b/lib/web_socket.rb index 633b59667..8c061388e 100644 --- a/lib/web_socket.rb +++ b/lib/web_socket.rb @@ -69,7 +69,9 @@ module Session next if !user # start user thread + start_user_thread = false if !@@user_threads[user.id] + start_user_thread = true @@user_threads[user.id] = Thread.new { UserState.new(user.id) @@user_threads[user.id] = nil @@ -77,6 +79,11 @@ module Session } end + # wait with client thread unil user thread has done some little work + if start_user_thread + sleep 0.4 + end + # start client thread if !@@client_threads[client_id] @@client_threads[client_id] = Thread.new {