{"id":16655475,"url":"https://github.com/dominicletz/debouncer","last_synced_at":"2026-03-02T02:35:44.405Z","repository":{"id":43704025,"uuid":"242800968","full_name":"dominicletz/debouncer","owner":"dominicletz","description":"Elixir debouncer library","archived":false,"fork":false,"pushed_at":"2023-11-24T16:27:44.000Z","size":26,"stargazers_count":8,"open_issues_count":0,"forks_count":2,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-09T18:13:18.724Z","etag":null,"topics":["elixir"],"latest_commit_sha":null,"homepage":"https://hexdocs.pm/debouncer/","language":"Elixir","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/dominicletz.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}},"created_at":"2020-02-24T17:38:34.000Z","updated_at":"2024-11-29T15:47:41.000Z","dependencies_parsed_at":"2023-11-24T17:31:35.019Z","dependency_job_id":"4e8d4f12-ea33-48e8-aae9-2d8babf24419","html_url":"https://github.com/dominicletz/debouncer","commit_stats":{"total_commits":16,"total_committers":2,"mean_commits":8.0,"dds":0.0625,"last_synced_commit":"cb2a9e3853b151c08afcf88365b83519a844848e"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dominicletz%2Fdebouncer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dominicletz%2Fdebouncer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dominicletz%2Fdebouncer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dominicletz%2Fdebouncer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dominicletz","download_url":"https://codeload.github.com/dominicletz/debouncer/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248085327,"owners_count":21045139,"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":["elixir"],"created_at":"2024-10-12T09:53:09.145Z","updated_at":"2026-03-02T02:35:44.377Z","avatar_url":"https://github.com/dominicletz.png","language":"Elixir","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Debouncer ![Build](https://github.com/dominicletz/debouncer/actions/workflows/test.yml/badge.svg)\n\nDebouncer module to reduce frequency of function calls to alerts, updates and similar. It supports four different modes:\n\n* `apply()`      - For delayed triggers, e.g. to trigger an __autocomplete__ action\n* `immediate()`  - For reducing frequency of events, the first event per interval is delivered immediately, e.g. trigger __data processing tasks__ \n* `immediate2()` - Similiar to immediate but never delays events, either forwards them or ignores them, e.g. to trigger __alert emails__ \n* `delay()`      - Only triggers an event after the timeout period, any further event delays the trigger. E.g. to detect data streams that __ended actvitiy__ \n\n## Usage Example\n\n```elixir\n  Debouncer.apply(SomeKey, fn() -\u003e \n    IO.puts(\"Hello World, debounced will appear in 5 seconds\") \n  end)\n```\n\n```elixir\n  Debouncer.immediate(OtherKey, fn() -\u003e \n    IO.puts(\"Hello World, will appear immediate, but not again within 5 seconds\") \n  end)\n```\n\n## Behaviour Graph\n\n```\nEVENT        E1---E2------E3-------E4----------\nTIMEOUT      ----------|----------|----------|-\n===============================================\napply()      ----------E2---------E3---------E4\nimmediate()  E1--------E2---------E3---------E4\nimmediate2() E1-----------E3-------------------\ndelay()      --------------------------------E4\n\nUSE CASE\napply()      - Search input field\nimmediate()  - Send email now, but not too freq\nimmediate2() - Game gun with reload time\ndelay()      - Schedule post-processing job\n```\n\nThis graph represents when the different variants fire an event respectively on a timeline. In code the first line would look like this:\n\n```elixir\nfn -\u003e\n  Debouncer.apply(SomeKey, fn() -\u003e IO.puts(\"X1\") end, 1000)\n  Process.sleep(500)\n  Debouncer.apply(SomeKey, fn() -\u003e IO.puts(\"X2\") end, 1000)\n  Process.sleep(800)\n  Debouncer.apply(SomeKey, fn() -\u003e IO.puts(\"X3\") end, 1000)\n  Process.sleep(900)\n  Debouncer.apply(SomeKey, fn() -\u003e IO.puts(\"X4\") end, 1000)\n  Process.sleep(1200)\nend.()\n\n\u003e X2\n\u003e X3\n\u003e X4\n```\n\n## Shorthands\n\nWhen using Module-Function-Argument tuples as callbacks (aka `mfa`) it can be convenient to skip the key and use the mfa itself as key:\n\n```elixir\n# Call later() function immediately with the default 5 second debounce:\nDebouncer.immediate({__MODULE__, :later, []})\n\n# Call later() function immediately with 1 second debounce:\nDebouncer.immediate({__MODULE__, :later, []}, 1_000)\n\n# Same but in using method binding\nDebouncer.immediate(\u0026later/0, 1_000)\n\n# Same but in using method binding\nDebouncer.immediate(\u0026later/0, 1_000)\n```\n\n**NOTE**\n\nDo not use in-place fun definitions can not be used in the shorthand, as those create a different key on every.\n\nExample:\n\n```elixir\n# Because (`fn -\u003e 1 end != fn -\u003e 1 end`) don't do this:\nDebouncer.immediate(fn -\u003e later() end, 1_000)\n```\n\n\n## Installation\n\nThe debouncer can be installed by adding `debouncer` to your list of dependencies in `mix.exs`:\n\n```elixir\ndef deps do\n  [\n    {:debouncer, \"~\u003e 1.0\"}\n  ]\nend\n```\n\nThe docs can be found at [https://hexdocs.pm/debouncer](https://hexdocs.pm/debouncer).\n\n## Remarks\n\nThe `delay()` behaviour is the same as in Michal Muskalas Debounce implementation https://github.com/michalmuskala/debounce","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdominicletz%2Fdebouncer","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdominicletz%2Fdebouncer","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdominicletz%2Fdebouncer/lists"}