{"id":18135509,"url":"https://github.com/whitfin/global-lazy","last_synced_at":"2025-04-19T14:09:39.780Z","repository":{"id":62429846,"uuid":"151885896","full_name":"whitfin/global-lazy","owner":"whitfin","description":"Lazy global initialization for Elixir, without state","archived":false,"fork":false,"pushed_at":"2021-02-22T18:11:12.000Z","size":7,"stargazers_count":4,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-11T13:40:18.808Z","etag":null,"topics":["global-state","initialization","lazy-loading"],"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":"2018-10-06T22:10:47.000Z","updated_at":"2024-06-30T18:53:14.000Z","dependencies_parsed_at":"2022-11-01T20:09:36.898Z","dependency_job_id":null,"html_url":"https://github.com/whitfin/global-lazy","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/whitfin%2Fglobal-lazy","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/whitfin%2Fglobal-lazy/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/whitfin%2Fglobal-lazy/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/whitfin%2Fglobal-lazy/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/whitfin","download_url":"https://codeload.github.com/whitfin/global-lazy/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249709414,"owners_count":21313948,"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":["global-state","initialization","lazy-loading"],"created_at":"2024-11-01T14:08:02.289Z","updated_at":"2025-04-19T14:09:39.759Z","avatar_url":"https://github.com/whitfin.png","language":"Elixir","funding_links":[],"categories":[],"sub_categories":[],"readme":"# GlobalLazy\n[![Build Status](https://img.shields.io/github/workflow/status/whitfin/global-lazy/CI)](https://github.com/whitfin/global-lazy/actions) [![Hex.pm Version](https://img.shields.io/hexpm/v/global_lazy.svg)](https://hex.pm/packages/global_lazy) [![Documentation](https://img.shields.io/badge/docs-latest-blue.svg)](https://hexdocs.pm/global_lazy/)\n\n**NOTE:** _This library is deprecated in favour of [whitfin/global-flags](https://github.com/whitfin/global-flags). You should migrate when possible as this library will not receive updates - it only exists to avoid\nbreaking existing applications._\n\nThis library is designed to provide an easy way to lazily initial global\nstate in Elixir, without having to be linked to a main application tree.\n\nThis is useful for libraries which always require certain state, regardless\nof the state of the parent application. It's aimed at use cases where it's\nslow to have a separate process, and it's wasteful to start an ETS table.\n\nThis library is tiny, so you can include it with minimal overhead.\n\n## Installation\n\nTo install it for your project, you can pull it directly from Hex. Rather\nthan use the version shown below, you can use the the latest version from\nHex (shown at the top of this README).\n\n```elixir\ndef deps do\n  [{:global_lazy, \"~\u003e 1.0\"}]\nend\n```\n\nDocumentation and examples can be found on [Hexdocs](https://hexdocs.pm/global_lazy/)\nas they're updated automatically alongside each release.\n\n## Usage\n\nAs mentioned above, the API is extremely small, so there's really only one thing to\nlearn how to use. Below is an example of lazily initializing an `Agent`, used to keep\ntrack of a global counter.\n\n```elixir\ndefmodule MyLibrary do\n\n  @doc \"\"\"\n  Retrieves the next integer in the global counter.\n  \"\"\"\n  def next_int do\n    # initializes the Agent only the first time called\n    GlobalLazy.init(\"my_library:started\", fn -\u003e\n      Agent.start(fn -\u003e 1 end, [ name: :my_library_agent ])\n    end)\n\n    # guaranteed to now have a started Agent\n    Agent.get_and_update(:my_library_agent, fn count -\u003e\n      {count, count + 1}\n    end)\n  end\nend\n```\n\nYou should handle all errors inside the provided function; feel free to just crash if you'd\nprefer to retry initialization on the next call - the flag is only switched if the function\nreturns successfully. You should also be careful to namespace your flags, because they're\nglobal (duh).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwhitfin%2Fglobal-lazy","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwhitfin%2Fglobal-lazy","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwhitfin%2Fglobal-lazy/lists"}