{"id":32692057,"url":"https://github.com/otters/gleam_manifold","last_synced_at":"2025-11-09T14:04:21.147Z","repository":{"id":321421097,"uuid":"1084827268","full_name":"otters/gleam_manifold","owner":"otters","description":"Type-safe bindings to `discord/manifold` for Gleam","archived":false,"fork":false,"pushed_at":"2025-10-29T14:06:14.000Z","size":20,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-10-29T16:07:59.865Z","etag":null,"topics":["beam","discord","erlang","gleam","message-passing"],"latest_commit_sha":null,"homepage":"https://otters.app","language":"Gleam","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/otters.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,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2025-10-28T08:07:01.000Z","updated_at":"2025-10-29T14:06:18.000Z","dependencies_parsed_at":"2025-10-29T16:08:09.223Z","dependency_job_id":"965d9696-d67b-4a53-b4ae-a9d3c1e570ea","html_url":"https://github.com/otters/gleam_manifold","commit_stats":null,"previous_names":["otters/gleam_manifold"],"tags_count":null,"template":false,"template_full_name":null,"purl":"pkg:github/otters/gleam_manifold","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/otters%2Fgleam_manifold","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/otters%2Fgleam_manifold/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/otters%2Fgleam_manifold/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/otters%2Fgleam_manifold/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/otters","download_url":"https://codeload.github.com/otters/gleam_manifold/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/otters%2Fgleam_manifold/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":282158385,"owners_count":26623999,"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-11-01T02:00:06.759Z","response_time":61,"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":["beam","discord","erlang","gleam","message-passing"],"created_at":"2025-11-01T15:02:09.189Z","updated_at":"2025-11-09T14:04:21.139Z","avatar_url":"https://github.com/otters.png","language":"Gleam","funding_links":[],"categories":[],"sub_categories":[],"readme":"# gleam_manifold\n\nGleam bindings to [Manifold](https://github.com/discord/manifold) - an Elixir library for fast message passing between BEAM nodes.\n\n## What is Manifold?\n\nManifold is an Elixir library developed by Discord that optimizes sending the same message to many processes. Instead of sending messages sequentially (which can be slow with thousands of processes), Manifold uses a divide-and-conquer approach that distributes the work across multiple sender processes, achieving much better performance at scale.\n\n## Installation\n\nAdd to your `gleam.toml` as a git dependency:\n\n```toml\n[dependencies]\ngleam_manifold = { git = \"git@github.com:otters/gleam_manifold.git\", ref = \"\u003ccommit hash\u003e\" }\n```\n\n## Usage\n\n### Creating and using Subjects\n\nThis library provides its own Subject type for type-safe message passing:\n\n```gleam\nimport gleam/erlang/process\nimport gleam_manifold as manifold\n\npub fn example() {\n  let subject = manifold.new_subject()\n  let pid = process.self()\n\n  // Send a message through Manifold\n  manifold.send(pid, subject, \"Hello world\")\n\n  // Receive the message\n  let assert Ok(message) = manifold.receive(subject, 1000)\n}\n```\n\n### Multicasting to multiple PIDs\n\nSend the same message to multiple processes at once:\n\n```gleam\nimport gleam/erlang/process\nimport gleam_manifold as manifold\n\npub fn broadcast(pids: List(process.Pid), message: String) {\n  let subject = manifold.new_subject()\n  manifold.send_multi(pids, subject, message)\n}\n```\n\n### Advanced Options\n\nThe library supports the same options as the Elixir Manifold library for tuning performance:\n\n#### Pack Modes\n\nControl how messages are serialized before sending:\n\n```gleam\nimport gleam_manifold as manifold\n\npub fn send_with_packing() {\n  let subject = manifold.new_subject()\n  let pid = process.self()\n\n  // Binary packing - efficient for large messages sent to many processes\n  manifold.send_with_options(\n    pid,\n    subject,\n    large_data,\n    [manifold.PackModeOption(manifold.Binary)]\n  )\n\n  // ETF (Erlang Term Format) - default behavior\n  manifold.send_with_options(\n    pid,\n    subject,\n    data,\n    [manifold.PackModeOption(manifold.Etf)]\n  )\n\n  // No packing\n  manifold.send_with_options(\n    pid,\n    subject,\n    data,\n    [manifold.PackModeOption(manifold.NoPacking)]\n  )\n}\n```\n\n#### Send Modes\n\nControl how messages are delivered:\n\n```gleam\nimport gleam_manifold as manifold\n\npub fn send_with_offload() {\n  let subject = manifold.new_subject()\n  let pids = get_many_pids()\n\n  // Offload mode - non-blocking, routes through sender processes\n  manifold.send_multi_with_options(\n    pids,\n    subject,\n    message,\n    [manifold.SendModeOption(manifold.Offload)]\n  )\n\n  // Direct mode (default) - sends directly\n  manifold.send_multi_with_options(\n    pids,\n    subject,\n    message,\n    [manifold.SendModeOption(manifold.Direct)]\n  )\n}\n```\n\n#### Combining Options\n\nYou can combine multiple options for fine-tuned control:\n\n```gleam\npub fn optimized_broadcast(pids: List(process.Pid), message: String) {\n  let subject = manifold.new_subject()\n\n  // Use binary packing with offload mode for optimal performance\n  manifold.send_multi_with_options(\n    pids,\n    subject,\n    message,\n    [\n      manifold.PackModeOption(manifold.Binary),\n      manifold.SendModeOption(manifold.Offload)\n    ]\n  )\n}\n```\n\n### Partitioner and Sender Keys\n\nControl load distribution across Manifold's internal processes:\n\n```gleam\nimport gleam_manifold as manifold\n\npub fn with_custom_routing() {\n  // Set a custom partitioner key for consistent routing\n  manifold.set_partitioner_key(\"user_123\")\n\n  // Set a custom sender key for offloaded messages\n  manifold.set_sender_key(\"channel_456\")\n\n  // Messages will be routed based on these keys\n  manifold.send(pid, subject, message)\n}\n```\n\nThis is useful for:\n\n- Ensuring message ordering for specific entities\n- Load balancing across partitioner processes\n- Preventing hot spots in message distribution\n\n## Testing\n\nRun the tests with:\n\n```bash\ngleam test\n```\n\n## License\n\nSee the LICENSE file in the repository.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fotters%2Fgleam_manifold","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fotters%2Fgleam_manifold","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fotters%2Fgleam_manifold/lists"}