{"id":13508623,"url":"https://github.com/whitfin/expool","last_synced_at":"2025-12-11T23:53:56.343Z","repository":{"id":62429391,"uuid":"48300316","full_name":"whitfin/expool","owner":"whitfin","description":"Extremely simple Process pooling and task submission in Elixir","archived":false,"fork":false,"pushed_at":"2020-03-03T19:54:48.000Z","size":23,"stargazers_count":29,"open_issues_count":1,"forks_count":2,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-06-09T12:50:07.209Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Elixir","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/whitfin.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}},"created_at":"2015-12-19T23:09:40.000Z","updated_at":"2025-05-13T03:34:25.000Z","dependencies_parsed_at":"2022-11-01T20:02:22.327Z","dependency_job_id":null,"html_url":"https://github.com/whitfin/expool","commit_stats":null,"previous_names":["zackehh/expool"],"tags_count":3,"template":false,"template_full_name":null,"purl":"pkg:github/whitfin/expool","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/whitfin%2Fexpool","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/whitfin%2Fexpool/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/whitfin%2Fexpool/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/whitfin%2Fexpool/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/whitfin","download_url":"https://codeload.github.com/whitfin/expool/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/whitfin%2Fexpool/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":263074780,"owners_count":23409820,"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-08-01T02:00:55.761Z","updated_at":"2025-12-11T23:53:56.288Z","avatar_url":"https://github.com/whitfin.png","language":"Elixir","readme":"# Expool\n[![Build Status](https://img.shields.io/travis/zackehh/expool.svg)](https://travis-ci.org/zackehh/expool) [![Coverage Status](https://img.shields.io/coveralls/zackehh/expool.svg)](https://coveralls.io/github/zackehh/expool) [![Hex.pm Version](https://img.shields.io/hexpm/v/expool.svg)](https://hex.pm/packages/expool) [![Documentation](https://img.shields.io/badge/docs-latest-yellowgreen.svg)](https://hexdocs.pm/expool/)\n\nA simple Process pooling library to avoid having to repeatedly write the boilerplate into your projects. Supports a couple of cool options, but nothing too crazy (yet). Basically just a way to abstract the spawning of processes and tasks, and ensure you're aware how concurrent your application is (i.e. avoid spawning off millions of procs accidentally).\n\n## Installation\n\nThe package can be installed via Hex:\n\n  1. Add expool to your list of dependencies in `mix.exs`:\n\n        def deps do\n          [{:expool, \"~\u003e 0.2.0\"}]\n        end\n\n  2. Ensure expool is started before your application:\n\n        def application do\n          [applications: [:expool]]\n        end\n\n## Usage\n\nThe general idea is that you create a pool and then submit tasks to it, pretty straightforward stuff:\n\n```elixir\n{ :ok, pid } = Expool.create_pool(3) # 3 workers\n\n# `worker_pid` is the Process submitted to, in case you wish\n# to send any messages.\n{ :ok, worker_pid } = Expool.submit(pid, fn -\u003e\n  :timer.sleep(5000)\n  IO.puts(\"Success!\")\nend)\n```\n\nOnce you're done with it, you can terminate your pool:\n\n```elixir\n{ :ok, pid } = Expool.create_pool(3)\n{ :ok, true } = Expool.terminate(pool)\n```\n\nTerminating means that all Processes referenced in the pool are killed using `:normal`. This means that sending messages to them will not work (because they're dead). To make this a little nicer, the pool returned by `terminate/1` has an internal flag marking the pool as inactive. This means that you'll receive an error tuple if you try to submit a task to it, allowing you to `case` on the submission.\n\n```elixir\n{ :ok, pid } = Expool.create_pool(3)\n{ :ok, true } = Expool.terminate(pool)\n\n{ :ok, worker_pid } = Expool.submit(pid, fn -\u003e\n  :timer.sleep(5000)\n  IO.puts(\"Success!\")\nend)\n\n** (MatchError) no match of right hand side value: {:error, \"Task submitted to inactive pool!\"}\n```\n\n## Options\n\n### args\n\nIt's sometimes nice to have your Agent supplied with arguments, so that you don't have to care about scoping. Due to this, Expool allows you to specify a list of arguments to be provided to your task scope. You do this by providing an `args` option to `create_pool`. This is either a list or a function (which returns a list). If you wish to pass a single list argument, remember to wrap it up, e.g. `[[head]]` (otherwise you would get `head` as an arg).\n\nIt should be noted that an `args` function is executed N times for the number of workers. This sounds stupid (and maybe it is), but the reasoning is that you might wish to open N different database connections. If you want to avoid this, just make your connection outside and then just pass in the list.\n\n```elixir\n{ :ok, pid } = Expool.create_pool(3, args: fn -\u003e\n  [my_database_client]\nend)\n\n{ :ok, worker_pid } = Expool.submit(pid, fn(client) -\u003e\n  :timer.sleep(5000)\n  IO.puts(\"Success with a client!\")\nend)\n```\n\n### name\n\nOne of the harder things to get used to with Elixir is the scoping; for this reason, you can add a `name` your pool (which literally just uses an `Agent` behind the scenes). This allows you to retrieve your pool from anywhere in your application effortlessly.\n\n```elixir\n# setup the pool\n{ :ok. pid } = Expool.create_pool(3, name: :mysql_pool)\n\n# somewhere else in your application\n{ :ok, pool } = Expool.get_pool(:mysql_pool)\n\n# you can submit to a registered name - this is one of the nicer\n# features, because you can blindly use Expool from anywhere\n{ :ok, worker_pid } = Expool.submit(:mysql_pool, fn -\u003e\n  :timer.sleep(5000)\n  IO.puts(\"Success!\")\nend)\n```\n\n### strategy\n\nBy default, Expool uses round-robin strategy methods to pass tasks to the pool. This will just rotate the index used for starting a task, before looping around all potential PIDs.\n\n```elixir\n{ :ok, pid } = Expool.create_pool(3, name: :mysql_pool, strategy: :round_robin)\n\n# this will shift the index\n{ :ok, worker_pid } = Expool.submit(pid, fn -\u003e\n  :timer.sleep(5000)\n  IO.puts(\"Success!\")\nend)\n\n# the next time you submit using `pid`, the\n# next process will receive the task\n{ :ok, worker_pid } = Expool.submit(pid, fn -\u003e\n  :timer.sleep(5000)\n  IO.puts(\"Success with a client!\")\nend)\n```\n\nThe only other currently available selection type is `:random` (which is literally just picking a process at random), but I may add load-based options in future.\n\n## Issues\n\nIf you find anything broken in here, please file an issue or a pull request. I wrote this whilst bored on a layover, so it's probably not the best, but it's in use in a couple of projects I'm working with.\n","funding_links":[],"categories":["Miscellaneous"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwhitfin%2Fexpool","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwhitfin%2Fexpool","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwhitfin%2Fexpool/lists"}