From 0fee37a63b588d84b4d91e5ad5074ffb71f698a4 Mon Sep 17 00:00:00 2001 From: David Vazgenovich Shakaryan Date: Mon, 14 Apr 2014 14:57:03 -0700 Subject: Multithreading and timeout functionality. --- dinobot.rb | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'dinobot.rb') diff --git a/dinobot.rb b/dinobot.rb index 052bb10..68c901a 100644 --- a/dinobot.rb +++ b/dinobot.rb @@ -1,4 +1,5 @@ require 'socket' +require 'timeout' module Dinobot class Bot @@ -44,10 +45,14 @@ module Dinobot str.chomp! puts "<< #{str.inspect}" - begin - parse_line(str) - rescue => e - puts "!! Error parsing line. (#{e})" + Thread.new do + begin + Timeout.timeout(30) do + parse_line(str) + end + rescue => e + puts "!! Error parsing line. (#{e})" + end end end -- cgit v1.2.3-70-g09d2