From: John-John Tedro Date: 2011-09-19T23:13:53+09:00 Subject: Re: how to implement method with execution timeout expiration? --0016e646a3a6d21d6f04ad4bf3d3 Content-Type: text/plain; charset=ISO-8859-1 On Mon, Sep 19, 2011 at 2:03 PM, Sub Zero wrote: > Hi, > Would you be so kind to advise me Player.get_action() implementation? > It should return value within timeout regardless of @connection > troubles. > > class Player > > def get_action( default_action, timeout_sec ) > self.within_timeout( timeout_sec ) do > @connection.get_action > end || default_action > end > > def Player.get_action timeout_sec &block > # what should be here ??? > ned > > end > > > action = Player.new( "Peter" ).get_action :fold, 30 > > Thank you inadvance! > > -- > Posted via http://www.ruby-forum.com/. > > This sounds more like a design issue, if your system blocks while @connection is running, you have few choices but create a separate thread, and wait for it (or destroy it on timeout). So my suggestions would either be. 1) Check if @connection supports some kind of timeout, 2) Use an event based system where the triggered event is bound to a connection and a timeout. The underlying system would either disconnect the actual request or mark it as invalid if or when an answer arrives. Good luck! -- John-John Tedro --0016e646a3a6d21d6f04ad4bf3d3--