Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

frugal_timeout

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

frugal_timeout

  • 0.0.14
  • Rubygems
  • Socket score

Version published
Maintainers
1
Created
Source

frugal_timeout

Build Status [![Coverage Status] (https://coveralls.io/repos/ledestin/frugal_timeout/badge.png)] (https://coveralls.io/r/ledestin/frugal_timeout) Code Climate

Ruby Timeout.timeout replacement using only 1 thread

Why

As you may know, the stock Timeout.timeout uses thread per timeout call. If you use it a lot, you will soon be out of threads. This gem is to provide an alternative that uses only 1 thread.

Also, there's a race condition in the 1.9-2.0 stock timeout. Consider the following code:

timeout(0.02) {
  timeout(0.01, IOError) { sleep }
}

In this case, the stock timeout will most likely raise IOError, but, given the race condition, sometimes it can also raise Timeout::Error. Just put `sleep 0.1' inside stock timeout ensure to trigger that. As of version 0.0.9, frugal_timeout will always raise IOError.

Example

require 'frugal_timeout'

begin
  FrugalTimeout.timeout(0.1) { sleep }
rescue Timeout::Error
  puts 'it works!'
end

# Ensure that calling timeout() will use FrugalTimeout.timeout().
FrugalTimeout.dropin!

# Rescue frugal-specific exception if needed.
begin
  timeout(0.1) { sleep }
rescue FrugalTimeout::Error
  puts 'yay!'
end

Installation

Tested on Ruby 1.9.3 and 2.0.0.

gem install frugal_timeout

FAQs

Package last updated on 02 Feb 2014

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc