Project

bonehead

0.0
No commit activity in last 3 years
No release in over 3 years
Retry blocks of code when they raise an exception.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.2
 Project Readme

Bonehead

Retry blocks of code when they raise an exception.

What is it?

def insist(tries = Float::Infinity, *exceptions, &block)

Bonehead executes a block. If an exception is raised in the block, it retries executing it. After tries failed tries, the exception is re-raised.

Usage

Retry on all exceptions inheriting from StandardError, just like rescue.

Bonehead.insist 3 do
  raise "Fail!"
end

Retry on specific exceptions only, just like rescue. The block below is 3 times.

Bonehead.insist 3, TypeError do
  raise TypeError, "Fail!"
end

And the one below only once.

Bonehead.insist 3, TypeError do
  raise "Fail!"
end

It's easy to wait a while between retries.

Bonehead.insist 3 do |try|
  sleep 0.1 if try > 1

  raise "Fail!"
end

Installation

gem install bonehead

Tests

Tests use cutest. Install Bonehead with development dependencies (gem install cutest --development) and run make test.

License

See the LICENSE file.