attempt
Version, currently 0.1.01 version
- 0.1.0latestJan 30, 2017
github.com/mosop/attempt
A tiny Crystal library for trying code blocks again and again.
0 stars
1 dependent
License: MIT
Installation
# Add this to your shard.yml
dependencies:
attempt:
github: mosop/attempt
version: ~> 0.1.0Then run:
shards installshard.yml
- Crystal
0.20.5- License
- MIT
- Author
- mosop
Dependencies
Runtime Dependencies
- calling~> 0.1.0github: mosop/calling
Development Dependencies
- stdio~> 0.1.3github: mosop/stdiodev
README
Attempt
A tiny Crystal library for trying code blocks again and again.
Installation
Add this to your application's shard.yml:
dependencies:
attempt:
github: mosop/attempt
Code Samples
Trying 5 Times
response = Attempt.times(5).start do
begin
response = HTTP::Client.get("http://unstable.net")
break response if response.success?
rescue
end
end
if response
puts response.body
else
raise "UNSTABLE!"
end
Wait 60 Sec. Before a Retry
response = Attempt.times(5).wait(60).start do
begin
response = HTTP::Client.get("http://unstable.net")
break response if response.success?
rescue
end
end
Every Hour Forever
Attempt.wait(60 * 60).start do
begin
response = HTTP::Client.get("http://api.cat.pics/links.json")
File.write("/path/to/kitty.json", response.body) if response.success?
rescue
end
end
Wait 10 Sec. Before the First Attempt
`rails s`
response = Attempt.prewait(10).start do
begin
response = HTTP::Client.get("http://localhost:3000")
break response if response.success?
rescue
end
end
Usage
require "attempt"
Documentation
Built from the current release. The first visit to a release nobody has asked for starts its build.
Links
This release
- Version
0.1.0- Tagged
- Jan 30, 2017
- Commit
88b9a5656a21- Crystal
0.20.5- Indexed
- yes
Dependents
Repository
github.com/mosop/attempt
Metadata
- Created
- Aug 18, 2026
- Updated
- Sep 26, 2026
- Synced
- Sep 26, 2026
- Versions
- 1