{"id":17188264,"url":"https://github.com/jclem/q-defer","last_synced_at":"2025-04-13T19:14:37.858Z","repository":{"id":9389220,"uuid":"11250929","full_name":"jclem/q-defer","owner":"jclem","description":"A lightweight promises implementation in Ruby","archived":false,"fork":false,"pushed_at":"2016-09-29T16:01:36.000Z","size":5,"stargazers_count":66,"open_issues_count":0,"forks_count":1,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-04-10T17:31:12.099Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://rubygems.org/gems/q-defer","language":"Ruby","has_issues":false,"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/jclem.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2013-07-08T09:42:42.000Z","updated_at":"2022-07-30T17:56:47.000Z","dependencies_parsed_at":"2022-07-21T11:59:06.475Z","dependency_job_id":null,"html_url":"https://github.com/jclem/q-defer","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jclem%2Fq-defer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jclem%2Fq-defer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jclem%2Fq-defer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jclem%2Fq-defer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jclem","download_url":"https://codeload.github.com/jclem/q-defer/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248766769,"owners_count":21158301,"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":[],"created_at":"2024-10-15T01:08:33.086Z","updated_at":"2025-04-13T19:14:37.836Z","avatar_url":"https://github.com/jclem.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Q\n\nQ is a lightweight promise implementation in Ruby.\n\n**DON'T USE ME!** This project doesn't follow any promises spec. It's all wrong.\n\n## Installation\n\nAdd this line to your application's Gemfile:\n\n    gem 'q-defer', require: 'q'\n\nAnd then execute:\n\n    $ bundle\n\nOr install it yourself as:\n\n    $ gem install q-defer\n\n## Usage\n\nDefer a single block:\n\n```ruby\nrequire \"open-uri\"\n\nQ.defer do |defer|\n  Thread.new do\n    response = open(\"http://www.example.com\")\n\n    if response.status[0] == \"200\"\n      defer.resolve(response)\n    else\n      defer.reject([response.status, response])\n    end\n  end\nend.then do |result|\n  puts \"ok\"\nend.fail do |err, result|\n  puts \"status code: #{err[0]}\"\nend.always do\n  puts \"All finished!\"\nend\n```\n\nDefer multiple blocks:\n\n```ruby\ndef defer_open(url)\n  Q.defer do |defer|\n    Thread.new do\n      response = open(\"http://www.example.com\")\n\n      if response.status[0] == \"200\"\n        defer.resolve(response)\n      else\n        defer.reject([response.status, response])\n      end\n    end\n  end\nend\n\nQ.when([\n  defer_open(\"http://www.example.com\"),\n  defer_open(\"http://www.google.com\")\n]).then do |results|\n  puts \"All successful!\"\nend.fail do |err, results|\n  puts \"Error: #{err}\"\nend.always do |results|\n  puts \"All successful or one failure.\"\nend\n```\n\n## Contributing\n\n1. Fork it\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 new Pull Request\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjclem%2Fq-defer","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjclem%2Fq-defer","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjclem%2Fq-defer/lists"}