ruby - Catching client connection disconnect in redis subscription -


i'm trying build notifications system redis , sinatra streams. can't seem catch when connection closes down, blocking redis subscription block seems never close down. best way achieve this?

get '/user/:id/next_notification' stream :keep_open |out|      $redis.subscribe("notifications:#{params[:id]}") { |on|          on.message { |channel, msg|             $redis.unsubscribe             out << msg         }     }      out.callback {          puts "unsub"         # $redis.unsubscribe      }      out.errback {          puts "unsub"         # $redis.unsubscribe     }   end end 

redis subscription blocking call. need execute in separate thread. dunno how in ruby. i'm sure there must threading library in ruby.

wrap blocking call in try..catch , know when connection has closed server side.


Comments

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -