From: Robert Klemme Date: 2011-09-20T17:04:49+09:00 Subject: Re: how to implement method with execution timeout expiration? On Mon, Sep 19, 2011 at 4: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! 10:00:52 Temp$ irb19 Ruby version 1.9.2 irb(main):001:0> require 'timeout' => true irb(main):002:0> timeout(10) { puts 123 } 123 => nil irb(main):003:0> timeout(10) { sleep 11; puts 123 } Timeout::Error: execution expired from (irb):3:in `sleep' from (irb):3:in `block in irb_binding' from (irb):3 from /opt/bin/irb19:12:in `
' Kind regards robert -- remember.guy do |as, often| as.you_can - without end http://blog.rubybestpractices.com/