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

timeouter

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

timeouter

  • 0.1.3.38794
  • Rubygems
  • Socket score

Version published
Maintainers
1
Created
Source

Timeouter

Gem Version Gem YARD

Coverage Quality Outdated Vulnerabilities

Timeouter is advisory timeout helper without any background threads.

Usage

Typical usage scenario:

require 'timeouter'

Timeouter::run(3) do |t|
  sleep 1 # do some work

  puts t.elapsed    # 1.00011811
  puts t.left       # 1.99985717 or nil if timeout was 0
  puts t.exhausted? # false or nil if timeout was 0
  puts t.running?   # true
  puts t.running!   # true

  sleep 3 # do another work

  puts t.elapsed    # 4.000177464
  puts t.left       # 0 or nil if timeout was 0
  puts t.exhausted? # true or nil if timeout was 0
  puts t.running?   # false
  puts t.running!   # raise Timeouter::TimeoutError.new('execution expired')
end

You can pass exception class and message on creation or on checking:

Timeouter::run(1, eclass: RuntimeError, message: 'error') do |t|
  sleep 2
  puts t.running!(eclass: MyError, message: 'myerror')
end

Loop helper:

# just loop 3 seconds
Timeouter::loop(3) do |t|
  puts "i'am in loop"
  sleep 1
end

# just loop 3 seconds and raise exception then
Timeouter::loop!(3, eclass: MyError) do |t|
  puts "i'am in loop and not raised yet"
  sleep 1
end

# Break the loop after some success and retuel value
result = Timeouter::loop!(3) do |t|
  puts "i'am in loop and not raised yet"
  if t.elapsed > 1
    puts "work done breaking loop"
    break "RESULT"
  end
  sleep 1
end

Installation

It's a gem:

  gem install timeouter

There's also the wonders of the Gemfile:

  gem 'timeouter'

FAQs

Package last updated on 12 Oct 2020

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