{"id":19032500,"url":"https://github.com/creadone/cocoon","last_synced_at":"2025-07-08T04:33:57.482Z","repository":{"id":70234122,"uuid":"341393081","full_name":"creadone/cocoon","owner":"creadone","description":"Wrapper for IO such as third-party API calls to prevent sudden blow up the main program","archived":false,"fork":false,"pushed_at":"2021-03-05T07:33:45.000Z","size":7,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-01-02T04:27:37.844Z","etag":null,"topics":["api","crystal","fibers"],"latest_commit_sha":null,"homepage":"","language":"Crystal","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/creadone.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-02-23T01:43:45.000Z","updated_at":"2023-03-05T00:55:52.000Z","dependencies_parsed_at":"2023-07-29T09:16:01.336Z","dependency_job_id":null,"html_url":"https://github.com/creadone/cocoon","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/creadone%2Fcocoon","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/creadone%2Fcocoon/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/creadone%2Fcocoon/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/creadone%2Fcocoon/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/creadone","download_url":"https://codeload.github.com/creadone/cocoon/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":240082645,"owners_count":19745259,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["api","crystal","fibers"],"created_at":"2024-11-08T21:29:02.716Z","updated_at":"2025-02-21T20:28:01.300Z","avatar_url":"https://github.com/creadone.png","language":"Crystal","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Cocoon\n\nWrapper for IO such as third-party API calls to prevent sudden blow up the main program.\n\n## Installation\n\n1. Add the dependency to your `shard.yml`:\n\n```yaml\ndependencies:\n  cocoon:\n    github: creadone/cocoon\n```\n\n2. Run `shards install`\n\n## Usage\n\n```crystal\nrequire \"cocoon\"\nrequire \"http/client\"\n\nalias Response = HTTP::Client::Response\ncocoon = Cocoon::Wrapper(Response).new\n\nloop do\n  result = cocoon.wrap do\n    if Random.rand \u003e 0.5\n      HTTP::Client.get(\"https://github.com\")\n    else\n      raise \"Connection is lost\"\n    end\n  end\n\n  # something in the \u0026block raised Exception\n  if result.is_a?(Exception)\n    puts result.message\n  end\n\n  # \u0026block is done\n  if result.is_a?(Response)\n    puts \"X-GitHub-Request-Id: #{result.headers[\"X-GitHub-Request-Id\"]}\"\n  end\n\n  # \u0026block has no result or task is not ended yet\n  if result.is_a?(Nil)\n    puts \"Nothing...\"\n  end\n\n  sleep 1\nend\n\n# =\u003e Nothing...\n# =\u003e X-GitHub-Request-Id: EF51:10C35:3A33E0D:3BCCF8A:603C72E7\n# =\u003e Connection is lost\n# =\u003e X-GitHub-Request-Id: EF52:0AF5:44114C4:45B5044:603C72E9\n# =\u003e X-GitHub-Request-Id: EF53:E298:B55ADC:B9B0DF:603C72EA\n# =\u003e Connection is lost\n# =\u003e Connection is lost\n```\n\n## Contributing\n\n1. Fork it (\u003chttps://github.com/creadone/cocoon/fork\u003e)\n2. Create your feature branch (`git checkout -b my-new-feature`)\n3. Commit your changes (`git commit -am 'Add some feature'`)\n4. Push to the branch (`git push origin my-new-feature`)\n5. Create a new Pull Request\n\n## Contributors\n\n- [creadone](https://github.com/creadone) - creator and maintainer\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcreadone%2Fcocoon","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcreadone%2Fcocoon","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcreadone%2Fcocoon/lists"}