<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Slash Dot Dash &#187; ruby</title>
	<atom:link href="http://www.slashdotdash.net/category/ruby/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.slashdotdash.net</link>
	<description>Rolling on Rails</description>
	<lastBuildDate>Wed, 18 Mar 2009 22:03:19 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Ruby Tidbit: Timeout code execution</title>
		<link>http://www.slashdotdash.net/2008/02/15/ruby-tidbit-timeout-code-execution/</link>
		<comments>http://www.slashdotdash.net/2008/02/15/ruby-tidbit-timeout-code-execution/#comments</comments>
		<pubDate>Fri, 15 Feb 2008 00:39:00 +0000</pubDate>
		<dc:creator>Ben</dc:creator>
				<category><![CDATA[Ruby on Rails]]></category>
		<category><![CDATA[ruby]]></category>

		<guid isPermaLink="false"></guid>
		<description><![CDATA[Just a small tip, if you wish to ensure a snippet of Ruby code doesn&#8217;t run for too long you can use the timeout function. You might want to do this when making a request to a remote server with net/http for example. timeout.rb A way of performing a potentially long-running operation in a thread, [...]]]></description>
			<content:encoded><![CDATA[<p>Just a small tip, if you wish to ensure a snippet of Ruby code doesn&#8217;t run for too long you can use the timeout function. You might want to do this when making a request to a remote server with <code>net/http</code> for example.</p>
<p><a href="http://www.ruby-doc.org/stdlib/libdoc/timeout/rdoc/index.html">timeout.rb</a></p>
<blockquote>
<p>A way of performing a potentially long-running operation in a thread, and terminating it‘s execution if it hasn‘t finished within fixed amount of time.</p>
</blockquote>
<p>Here&#8217;s a quick example using the excellent <a href="http://rfeedparser.rubyforge.org/">rFeedParser</a> (Universal Feed Parser in Ruby) to fetch an <span class="caps">RSS</span> feed.</p>
<pre>
require 'timeout'
require 'zlib'
require 'rubygems'
require 'rfeedparser'

fp = nil
begin
  # Don't take longer than 20 seconds to retrieve &#38; parse an RSS feed
  Timeout::timeout(20) do
    fp = FeedParser.parse("http://feeds.feedburner.com/slashdotdash")
  end
rescue Timeout::Error
  # Too slow!!
end
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.slashdotdash.net/2008/02/15/ruby-tidbit-timeout-code-execution/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
