retrycr

Version, currently 0.1.03 versions

github.com/taylorfinnell/retrycr

Retry blocks of Crystal code

12 stars
2 dependents
License: MIT

Nothing has been indexed for 0.1.0 yet. The tag is recorded, its shard.yml has not been read, so the manifest and dependency list below are empty because they are unknown rather than because they are absent.

Installation

# Add this to your shard.yml
dependencies:
  retrycr:
    github: taylorfinnell/retrycr
    version: ~> 0.1.0

Then run:

shards install

shard.yml

No shard.yml has been indexed for 0.1.0. You can read it on the repository.

Dependencies

Unknown: the shard.yml for this version has not been read yet.

README

This README is the one indexed from the repository at its latest ref, not from the tag for this version.

retrycr

Build Status

Retry blocks of Crystal code.

Installation

Add this to your application's shard.yml:

dependencies:
  retrycr:
    github: taylorfinnell/retrycr

Usage

require "retrycr"

Retry all exceptions.

retryable(tries: 1, wait: 1) do
  # my code
end

You may specify which Exception classes trigger a retry.

retryable(on: ArgumentError | Base64::Error, tries: 1, wait: 1) do
  # my code
end

The wait parameter can either be an Int32 or a Proc.

retryable(tries: 1, wait: ->(x : Int32) { 2**x }) do
  # my code
end

The number of retries that have happened is yielded to the block.

retryable(tries: 1, wait: 1) do |retries|
  puts "There have been #{retries} retries!"
end

You can specify a callback to run everytime the code is retried.

callback = -> (ex : Exeption) { "The code is about to be retried!" }
retryable(tries: 1, wait: 1, callback: callback) do |retries|
  puts "There have been #{retries} retries!"
end

You can specify a callback to run after all retries are exhausted.

f = File.open("test")
callback = -> (retries : Int32) { f.close }
retryable(tries: 1, wait: 1, finally: callback) do |retries|
  f.read
end