{"id":17130697,"url":"https://github.com/jechol/buffered","last_synced_at":"2025-04-13T07:34:04.925Z","repository":{"id":43340941,"uuid":"296504334","full_name":"jechol/buffered","owner":"jechol","description":"Buffered Queue and Counter for Elixir","archived":false,"fork":false,"pushed_at":"2024-04-10T09:47:26.000Z","size":32,"stargazers_count":4,"open_issues_count":4,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-02-15T07:12:14.768Z","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":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jechol.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2020-09-18T03:32:31.000Z","updated_at":"2024-05-21T22:46:36.000Z","dependencies_parsed_at":"2023-10-19T16:45:10.303Z","dependency_job_id":null,"html_url":"https://github.com/jechol/buffered","commit_stats":{"total_commits":38,"total_committers":2,"mean_commits":19.0,"dds":0.07894736842105265,"last_synced_commit":"070bf5eeff2782cdbca6614f0945839c1e993cf2"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jechol%2Fbuffered","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jechol%2Fbuffered/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jechol%2Fbuffered/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jechol%2Fbuffered/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jechol","download_url":"https://codeload.github.com/jechol/buffered/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":239690074,"owners_count":19681035,"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-10-14T19:12:59.645Z","updated_at":"2025-02-23T01:31:14.266Z","avatar_url":"https://github.com/jechol.png","language":"Elixir","funding_links":[],"categories":[],"sub_categories":[],"readme":"![mix test](https://github.com/jechol/buffered/workflows/mix%20test/badge.svg)\n![Hex.pm](https://img.shields.io/hexpm/v/buffered)\n\n# Buffered\n\nBuffered queue and counter for Erlang/Elixir\n\n## Installation\n\nIf [available in Hex](https://hex.pm/docs/publish), the package can be installed\nby adding `buffered` to your list of dependencies in `mix.exs`:\n\n```elixir\ndef deps do\n  [\n    {:buffered, \"~\u003e 0.4.0\"}\n  ]\nend\n```\n\n## Usage\n\n### Queue\n\n```elixir\nalias Buffered.Queue\n{:ok, pid} = Queue.start_link(%{size: 2, timeout: 3000}, \u0026IO.inspect/1)\n\nQueue.enqueue(pid, [1])\nQueue.enqueue(pid, [2, 3])\n# [1, 2, 3] immediately as size of [1, 2, 3] \u003e size 2\n\nQueue.enqueue(pid, [4])\nProcess.sleep(5000)\n# [4] as ellapsed time 5000ms \u003e timeout 3000ms\n\nQueue.enqueue(pid, [5])\nQueue.flush(pid)\n# [5] due to flush\n```\n\n### Counter\n\n```elixir\nalias Buffered.Counter\n{:ok, pid} = Counter.start_link(%{start: 100, threshold: 10, timeout: 3000}, \u0026IO.inspect/1)\n\nCounter.add(pid, 9)\nCounter.add(pid, 2)\n# 111 immediately as change 11 \u003e threshold 10\n\nCounter.add(pid, 2)\nProcess.sleep(5000)\n# 113 as ellapsed time 5000ms \u003e timeout 3000ms\n\nCounter.add(pid, -8)\nCounter.flush(pid)\n# 105 due to flush\n```\n\n### How to extend?\n\nBoth of `Buffered.Counter`, `Buffered.Queue` are just customization of `Buffered`.\n\nDefining `append/2`, `overflow?/1`, `reset/1` for your own data is enough.\n\nSee how `Buffered.Queue` is implemented [here](https://github.com/jechol/buffered/blob/master/lib/buffered/queue.ex).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjechol%2Fbuffered","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjechol%2Fbuffered","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjechol%2Fbuffered/lists"}