{"id":13880280,"url":"https://github.com/dotboris/eldritch","last_synced_at":"2025-07-16T16:31:29.532Z","repository":{"id":15197773,"uuid":"17925986","full_name":"dotboris/eldritch","owner":"dotboris","description":"A ruby DSL that adds concurrent programming constructs to make parallelism easier.","archived":false,"fork":false,"pushed_at":"2019-01-04T23:04:31.000Z","size":93,"stargazers_count":277,"open_issues_count":3,"forks_count":5,"subscribers_count":8,"default_branch":"master","last_synced_at":"2025-07-10T03:14:28.090Z","etag":null,"topics":["async-methods","dsl","ruby"],"latest_commit_sha":null,"homepage":"","language":"Ruby","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/dotboris.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":"2014-03-20T00:52:13.000Z","updated_at":"2025-02-14T15:51:51.000Z","dependencies_parsed_at":"2022-07-31T02:38:13.631Z","dependency_job_id":null,"html_url":"https://github.com/dotboris/eldritch","commit_stats":null,"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"purl":"pkg:github/dotboris/eldritch","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dotboris%2Feldritch","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dotboris%2Feldritch/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dotboris%2Feldritch/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dotboris%2Feldritch/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dotboris","download_url":"https://codeload.github.com/dotboris/eldritch/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dotboris%2Feldritch/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":265524632,"owners_count":23782016,"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":["async-methods","dsl","ruby"],"created_at":"2024-08-06T08:02:54.709Z","updated_at":"2025-07-16T16:31:29.181Z","avatar_url":"https://github.com/dotboris.png","language":"Ruby","readme":"Eldritch\n========\n\n[![Build Status](http://travis-ci.org/dotboris/eldritch.svg?branch=master)](http://travis-ci.org/dotboris/eldritch)\n[![Coverage Status](http://coveralls.io/repos/dotboris/eldritch/badge.png)](http://coveralls.io/r/dotboris/eldritch)\n[![Code Climate](http://codeclimate.com/github/dotboris/eldritch.png)](http://codeclimate.com/github/dotboris/eldritch)\n\n_The dark arts of concurrent programming._\n\nA DSL that adds parallel programming constructs to make your life a little\neasier.\n\nUsage\n-----\n\n1.  Install it `gem install eldritch`\n1.  Require it `require 'eldritch'`\n1.  Use it (see features below)\n\nBy default eldritch will inject the DSL into the global scope. If you don't want\nthis, you can require `eldritch/safe` instead of `eldritch`.\n\n```ruby\nrequire 'eldricth/safe'\n\nclass MyClass\n  include Eldritch::DSL\n  extend Eldritch::DSL\n\n  # The DSL is available in this class\nend\n```\n\nDevelopment\n-----------\n\n### Setup\n\n```sh\nbundler install\n```\n\n### Running tests\n\n```sh\nbundler exec rake\n```\n\n### Running examples\n\n```sh\nruby -I lib examples/{your favorite example}.rb\n```\n\n### Generate doc\n\n```sh\nbundle exec rake doc\n```\n\nFeatures\n--------\n\n### async methods\n\nAsync methods run concurrently when called. The caller is returned control right\naway and the method runs in the background.\n\n```ruby\nrequire 'eldritch'\n\n# define an async method\nasync def send_email(email)\n  # ...\nend\n\nsend_email(some_email) # runs in the background\n```\n\n#### ruby 1.9.3 and 2.0.0\n\nFor all versions of ruby before 2.1.0, you need to define async methods like so:\n\n```ruby\ndef foo\n  # stuff\nend\nasync :foo\n```\n\nSince ruby 2.1.0, def returns the name of the method defined as a symbol. This\nallows for the cleaner `async def foo` syntax.\n\n### async blocks\n\nAsync blocks are run concurrently.\n\n```ruby\nrequire 'eldritch'\n\nasync do\n  # runs in the background\nend\n```\n\n### tasks\n\nAsync blocks and async methods both return tasks. These can be used to interact\nwith the async block/method.\n\n```ruby\nrequire 'eldritch'\n\ntask = async do\n  # calculate something that will take a long time\nend\n\n# we need to result of the task\nres = 2 + task.value # waits for the task to finish\n```\n\n### together blocks\n\nTogether blocks are used to control all async blocks and methods within them as\na group. Before exiting, together blocks wait for all their async calls to be\ndone before returning.\n\n```ruby\nrequire 'eldritch'\n\ntogether do\n  1000.times do\n    async do\n      # do some work\n    end\n  end\nend\n# all 1000 tasks are done\n```\n\nThese blocks can also take an argument. This argument is a group that can be\nused to control the async calls in the block. See the documentation for\nEldritch::Group for more information.\n\n```ruby\nrequire 'eldritch'\n\ntogether do |group|\n  5.times do\n    async do\n      # do something\n      group.interrupt if some_condition  # stops all other tasks\n    end\n  end\nend\n```\n\nA note on GIL\n-------------\n\nMRI has this nasty little feature called a _GIL_ or _Global Interpreter Lock_.\nThis lock makes it so that only one thread can run at a time. Let's say that you\nhave 4 cores, running threaded code on MRI will only make use of 1 core.\nSometimes, you might not gain a speed boost if you make code parallel. This\ncould the case even if theory says otherwise.\n\nNot all ruby implementations use a _GIL_. For example, jRuby does not use a\n_GIL_.\n\nIf your ruby implementation has a _GIL_, you will probably see a speed boost if\nyour code does a lot of IO or anything that's blocking. In that case running on\na single core is not that much of a hindrance, because most of the threads will\nbe blocked and your code should run more often.\n","funding_links":[],"categories":["Ruby"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdotboris%2Feldritch","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdotboris%2Feldritch","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdotboris%2Feldritch/lists"}