{"id":17452359,"url":"https://github.com/omar-azmi/async-promise-ruby","last_synced_at":"2026-02-17T13:03:02.487Z","repository":{"id":257809209,"uuid":"865185544","full_name":"omar-azmi/async-promise-ruby","owner":"omar-azmi","description":"An Asynchronous Promise library for Ruby, built over \"async\" gem, providing Javascript ES6 style Promises. Also includes utilities like ES6-style \"fetch\" that return a Promise.","archived":false,"fork":false,"pushed_at":"2024-10-04T04:20:03.000Z","size":52,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-11-12T01:38:40.722Z","etag":null,"topics":["async","asynchronous","concurrency","es6","promise","ruby","ruby-gem","rubygem"],"latest_commit_sha":null,"homepage":"https://rubygems.org/gems/async-promise","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/omar-azmi.png","metadata":{"files":{"readme":"readme.md","changelog":"changelog.md","contributing":null,"funding":null,"license":"license.md","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":"2024-09-30T06:03:14.000Z","updated_at":"2024-10-04T04:23:23.000Z","dependencies_parsed_at":null,"dependency_job_id":"11ddb2cd-4704-468e-add0-96a6860e43a2","html_url":"https://github.com/omar-azmi/async-promise-ruby","commit_stats":null,"previous_names":["omar-azmi/async-promise-ruby"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/omar-azmi/async-promise-ruby","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/omar-azmi%2Fasync-promise-ruby","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/omar-azmi%2Fasync-promise-ruby/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/omar-azmi%2Fasync-promise-ruby/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/omar-azmi%2Fasync-promise-ruby/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/omar-azmi","download_url":"https://codeload.github.com/omar-azmi/async-promise-ruby/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/omar-azmi%2Fasync-promise-ruby/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29545295,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-17T13:00:00.370Z","status":"ssl_error","status_checked_at":"2026-02-17T12:57:14.072Z","response_time":100,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["async","asynchronous","concurrency","es6","promise","ruby","ruby-gem","rubygem"],"created_at":"2024-10-17T23:06:07.470Z","updated_at":"2026-02-17T13:03:02.460Z","avatar_url":"https://github.com/omar-azmi.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"# async-promise\n\n\n## Overview\n\nThis library provides Javascript-like promises to Ruby.\nIt allows you to create and manage asynchronous operations with ease, providing a familiar API for those who have worked with JavaScript promises.\n\nThis library provides a Ruby implementation of ES6-like JavaScript Promises.\nIt allows one to build asynchronous logic with ease, in addition to being able to handle exceptions.\nUnder the hood, this library uses the [async](https://github.com/socketry/async) gem for concurrency management.\n\n\n## Installation\n\nInstall the gem via `bundler` by executing:\n\n```shell\nbundle add async-promise\n```\n\n\n## Examples\n\n### Example 1: Basic promise resolution\n\nHere's how to create a new promise and resolve it with the value `\"Success!\"`.\nBy calling the `then` method on our `promise`, we get to hook additional tasks that should be carried out after the `promise` is settled.\nThe first lambda argument in the `then` method specifies the action to take if `promise` was resolved successfully.\nThe second lambda argument specifies the action to take if the `promise` was rejected.\n\n```rb\nrequire \"async\"\nrequire \"async/promise\"\n\nAsync do\n  promise = Async::Promise.new()\n\n  promise\n    .then(-\u003e(value) { puts \"Resolved with: #{value}\" }) # callback for success\n    .catch(-\u003e(reason) { puts \"Error: #{reason}\" })      # callback for failure\n\n  promise.resolve(\"Success!\")\n  # console output:\n  # Resolved with: Success!\nend\n```\n\n### Example 2: Chaining promises\n\nThis example demonstrates how to chain multiple `then` calls, passing the resolved value along the chain.\n\n```rb\nrequire \"async\"\nrequire \"async/promise\"\n\nAsync do\n  promise = Async::Promise.new()\n\n  promise\n    .then(-\u003e(value) { return \"#{value} World\" }) # Modify the value\n    .then(-\u003e(value) { return \"#{value}!\" })      # Further modify the value\n    .then(-\u003e(value) { puts value })              # Output the final value\n\n  promise.resolve(\"Hello\")\n  # console output:\n  # Hello World!\nend\n```\n\n### Example 3: Handling rejections\n\nThis example demonstrates how to handle promise rejections by using the `catch` method, or using the second argument of the `then` method.\n\n```rb\nrequire \"async\"\nrequire \"async/promise\"\n\nAsync do\n  promise1 = Async::Promise.new()\n\n  promise2 = promise1\n    .then(-\u003e(value) { puts \"Resolved with: #{value}\" }) # This won't be called\n    .catch(-\u003e(reason) {\n      puts \"Caught error: #{reason}\"\n      raise \"Error when catching error!?\"\n    }) # Error handling in addition to throwing another error, which is caught in the next `then` promise.\n    .then(\n      nil,\n      -\u003e(reason) {\n        puts \"Caught yet another error: #{reason}\"\n        return \"hEy b0ss!\"\n      }\n    )\n\n  promise1.reject(\"Something went wrong!\")\n  # console output:\n  # Caught error: Something went wrong!\n  # Caught yet another error: Error when catching error!?\n\n  puts promise2.wait # wait for the promise to get its resolved value\n  # console output:\n  # hEy b0ss!\n\n  # waiting for a rejected promise will raise an error\n  begin puts promise1.wait # an error will be raised here\n  rescue =\u003e error; puts error.message\n  end\n  # console output:\n  # Something went wrong!\nend\n```\n\n## Usage\n\nCheck out the type annotations and YARD doc comments in the [`./sig/async/promise.rbs`](./sig/async/promise.rbs) file.\nOtherwise, a summary follows:\n\n### Promise methods\n- `#status()`: Returns the current status of the promise: \"pending\", \"fulfilled\", or \"rejected\".\n- `#resolve(value)`: Fulfills the promise with the given `value`.\n- `#reject(reason)`: Rejects the promise with the provided `reason`.\n- `#then(on_resolve, on_reject)`: Chains asynchronous operations and provides handlers for resolution and rejection.\n- `#catch(on_reject)`: Catches errors that occurred in preceding promise chains.\n- `#wait`: Blocks the current execution until the promise is settled and returns the resolved value or raises an error if rejected.\n\n### Promise class methods\n- `.resolve(value)`: Creates a pre-resolved promise.\n- `.reject(reason)`: Creates a pre-rejected promise.\n- `.all(promises)`: Returns a promise that resolves when all input promises are resolved or rejects when any one of them is rejected.\n- `.race(promises)`: Returns a promise that settles as soon as any input promise is settled (either fulfilled or rejected).\n- `.timeout(resolve_in, reject_in, resolve, reject)`: Returns a promise that settles after a specified timeout, either resolving or rejecting.\n\n\n## Contributing\n\nBug reports and pull requests are welcome on GitHub at: [https://github.com/omar-azmi/async-promise-ruby](https://github.com/omar-azmi/async-promise-ruby).\n\n\n## Development\n\nClone the repo\n\n```shell\ngit clone https://github.com/omar-azmi/async-promise-ruby.git\n```\n\nInstall dependencies\n\n```shell\nbundle install\n```\n\nRun tests (in parallel)\n\n```shell\nbundle exec sus-parallel\n```\n\nMake changes to the source code and increment the library version.\n\nBuild the gem library file\n\n```shell\ngem build \"./async-promise.gemspec\"\n```\n\nPush the changes to [rubygems.org](https://rubygems.org)\n\n```shell\ngem push \"./async-promise-*.gem\"\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fomar-azmi%2Fasync-promise-ruby","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fomar-azmi%2Fasync-promise-ruby","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fomar-azmi%2Fasync-promise-ruby/lists"}