cocoon
Version, currently 0.1.05 versions
- 0.2.3latestMar 1, 2021
- 0.1.3not indexedMar 5, 2021
- 0.1.2not indexedMar 5, 2021
- 0.1.1not indexedMar 5, 2021
- 0.1.0not indexedMar 5, 2021
github.com/creadone/cocoon
Wrapper for IO such as third-party API calls to prevent sudden blow up the main program.
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:
cocoon:
github: creadone/cocoon
version: ~> 0.1.0Then run:
shards installshard.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.
Cocoon
Wrapper for IO such as third-party API calls to prevent sudden blow up the main program.
Installation
- Add the dependency to your
shard.yml:
dependencies:
cocoon:
github: creadone/cocoon
- Run
shards install
Usage
require "cocoon"
require "http/client"
alias Response = HTTP::Client::Response
cocoon = Cocoon::Wrapper(Response).new
loop do
result = cocoon.wrap do
if Random.rand > 0.5
HTTP::Client.get("https://github.com")
else
raise "Connection is lost"
end
end
# something in the &block raised Exception
if result.is_a?(Exception)
puts result.message
end
# &block is done
if result.is_a?(Response)
puts "X-GitHub-Request-Id: #{result.headers["X-GitHub-Request-Id"]}"
end
# &block has no result or task is not ended yet
if result.is_a?(Nil)
puts "Nothing..."
end
sleep 1
end
# => Nothing...
# => X-GitHub-Request-Id: EF51:10C35:3A33E0D:3BCCF8A:603C72E7
# => Connection is lost
# => X-GitHub-Request-Id: EF52:0AF5:44114C4:45B5044:603C72E9
# => X-GitHub-Request-Id: EF53:E298:B55ADC:B9B0DF:603C72EA
# => Connection is lost
# => Connection is lost
Contributing
- Fork it (https://github.com/creadone/cocoon/fork)
- Create your feature branch (
git checkout -b my-new-feature) - Commit your changes (
git commit -am 'Add some feature') - Push to the branch (
git push origin my-new-feature) - Create a new Pull Request
Contributors
- creadone - creator and maintainer
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
- Mar 5, 2021
- Commit
828ed95faf2a- Indexed
- not yet
Dependents
No indexed shard depends on this one yet.
Repository
github.com/creadone/cocoon
Metadata
- Created
- Aug 12, 2026
- Updated
- Aug 15, 2026
- Synced
- Aug 14, 2026
- Versions
- 5