{"id":30030101,"url":"https://github.com/longlene/dynamic_supervisor","last_synced_at":"2026-01-20T16:55:07.383Z","repository":{"id":307059225,"uuid":"1028225807","full_name":"longlene/dynamic_supervisor","owner":"longlene","description":"Dynamic Supervisor","archived":false,"fork":false,"pushed_at":"2025-07-29T08:30:52.000Z","size":0,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-07-29T08:45:36.678Z","etag":null,"topics":["erlang"],"latest_commit_sha":null,"homepage":"","language":"Erlang","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/longlene.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,"zenodo":null}},"created_at":"2025-07-29T08:03:56.000Z","updated_at":"2025-07-29T08:16:49.000Z","dependencies_parsed_at":"2025-07-29T08:45:38.474Z","dependency_job_id":"e7acd33b-349b-4619-b305-2262d4202392","html_url":"https://github.com/longlene/dynamic_supervisor","commit_stats":null,"previous_names":["longlene/dynamic_supervisor"],"tags_count":3,"template":false,"template_full_name":null,"purl":"pkg:github/longlene/dynamic_supervisor","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/longlene%2Fdynamic_supervisor","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/longlene%2Fdynamic_supervisor/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/longlene%2Fdynamic_supervisor/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/longlene%2Fdynamic_supervisor/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/longlene","download_url":"https://codeload.github.com/longlene/dynamic_supervisor/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/longlene%2Fdynamic_supervisor/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":269137306,"owners_count":24366552,"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","status":"online","status_checked_at":"2025-08-06T02:00:09.910Z","response_time":99,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"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":["erlang"],"created_at":"2025-08-06T19:00:25.661Z","updated_at":"2026-01-20T16:55:07.357Z","avatar_url":"https://github.com/longlene.png","language":"Erlang","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Dynamic Supervisor\n\n[![Hex.pm](https://img.shields.io/hexpm/v/dynamic_supervisor.svg)](https://hex.pm/packages/dynamic_supervisor)\n[![License](https://img.shields.io/hexpm/l/dynamic_supervisor.svg)](https://github.com/longlene/dynamic_supervisor/blob/master/LICENSE)\n\nAn Erlang library providing a supervisor optimized for dynamically spawning children. This is a port of Elixir's DynamicSupervisor, maintaining a similar API while following Erlang conventions.\n\n## Installation\n\nAdd to your `rebar.config`:\n\n```erlang\n{deps, [\n    {dynamic_supervisor, \"1.0.0\"}\n]}.\n```\n\nOr for hex.pm:\n\n```erlang\n{deps, [\n    {dynamic_supervisor, {hex, dynamic_supervisor, \"1.0.0\"}}\n]}.\n```\n\n## Overview\n\nThe `dynamic_supervisor` module provides a supervisor optimized for dynamically starting children. Unlike the standard supervisor which is designed for static children started in order, a dynamic supervisor:\n\n- Starts with no children\n- Allows starting children on demand via `start_child/2`\n- Has no ordering between children\n- Can efficiently handle millions of children\n- Executes operations like shutdown concurrently\n\n## Features\n\n- **One-for-one supervision strategy**: Only the failed child is restarted\n- **Dynamic child management**: Add and remove children at runtime\n- **Restart strategies**: Support for `permanent`, `transient`, and `temporary` restart types\n- **Maximum children limit**: Optional limit on the number of concurrent children\n- **Extra arguments**: Arguments that are prepended to child start arguments\n- **Full OTP compliance**: Implements standard supervisor behaviors\n\n## API\n\n### Starting a Dynamic Supervisor\n\n```erlang\n{ok, Pid} = dynamic_supervisor:start_link([\n    {name, {local, my_supervisor}},\n    {strategy, one_for_one},\n    {max_restarts, 3},\n    {max_seconds, 5},\n    {max_children, 1000}\n]).\n```\n\n### Starting Children\n\n```erlang\n%% Full child specification\n{ok, ChildPid} = dynamic_supervisor:start_child(my_supervisor, \n    #{id =\u003e worker1,\n      start =\u003e {my_worker, start_link, [Arg1, Arg2]},\n      restart =\u003e permanent,\n      shutdown =\u003e 5000,\n      type =\u003e worker,\n      modules =\u003e [my_worker]}).\n\n%% Simplified specification (using defaults)\n{ok, ChildPid2} = dynamic_supervisor:start_child(my_supervisor,\n    #{id =\u003e worker2,\n      start =\u003e {my_worker, start_link, []}}).\n```\n\n### Managing Children\n\n```erlang\n%% List all children\nChildren = dynamic_supervisor:which_children(my_supervisor).\n\n%% Count children\nCounts = dynamic_supervisor:count_children(my_supervisor).\n%% Returns: #{specs =\u003e N, active =\u003e N, supervisors =\u003e N, workers =\u003e N}\n\n%% Terminate a specific child\nok = dynamic_supervisor:terminate_child(my_supervisor, ChildPid).\n\n%% Stop the supervisor\nok = dynamic_supervisor:stop(my_supervisor).\n```\n\n## Examples\n\n### Basic Usage\n\nSee `example_usage.erl` for a complete example:\n\n```bash\nmake example\n```\n\n### Running Tests\n\n```bash\nmake test\n```\n\n### Interactive Shell\n\n```bash\nmake shell\n```\n\nThen in the Erlang shell, you need to add the examples path:\n\n```erlang\n1\u003e code:add_path(\"examples\").\n2\u003e example_usage:demo().\n```\n\n## Differences from Elixir's DynamicSupervisor\n\n1. **Module naming**: Uses Erlang convention (`dynamic_supervisor` instead of `DynamicSupervisor`)\n2. **Options format**: Uses proplist format `[{key, value}]` instead of keyword lists\n3. **Child specs**: Supports both map-based specs and traditional tuple-based specs\n4. **Return values**: Uses standard Erlang return conventions\n5. **Error handling**: Uses Erlang's error_logger instead of Elixir's Logger\n\n## Implementation Notes\n\n- Built on top of gen_server behavior\n- Uses maps for efficient child storage\n- Implements OTP supervisor protocols\n- Supports hot code upgrades via `code_change/3`\n- Proper cleanup on termination with concurrent child shutdown\n\n## Files\n\n- `src/dynamic_supervisor.erl` - Main implementation\n- `examples/counter.erl` - Example gen_server for demonstrations\n- `examples/example_usage.erl` - Usage examples\n- `test/` - Test suites (EUnit and Common Test)\n- `Makefile` - Build automation\n\n## Building\n\n```bash\nmake compile    # Compile the library\nmake test      # Run tests  \nmake example   # Run example\nmake shell     # Start Erlang shell\n```\n\n## Requirements\n\n- Erlang/OTP 21 or later (for map support)\n- rebar3 (for building)\n\n## License\n\nApache 2.0 - This implementation follows the structure of Elixir's DynamicSupervisor but is written entirely in Erlang.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flonglene%2Fdynamic_supervisor","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flonglene%2Fdynamic_supervisor","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flonglene%2Fdynamic_supervisor/lists"}