{"id":16936480,"url":"https://github.com/jonhoo/throttled-reader","last_synced_at":"2025-04-11T19:07:00.860Z","repository":{"id":57669735,"uuid":"120795052","full_name":"jonhoo/throttled-reader","owner":"jonhoo","description":"An io::Read proxy that limits calls to read()","archived":false,"fork":false,"pushed_at":"2018-12-04T18:50:27.000Z","size":10,"stargazers_count":7,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-11T01:48:31.646Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Rust","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/jonhoo.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE-APACHE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-02-08T17:38:47.000Z","updated_at":"2024-08-21T02:12:35.000Z","dependencies_parsed_at":"2022-09-26T20:40:35.394Z","dependency_job_id":null,"html_url":"https://github.com/jonhoo/throttled-reader","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jonhoo%2Fthrottled-reader","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jonhoo%2Fthrottled-reader/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jonhoo%2Fthrottled-reader/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jonhoo%2Fthrottled-reader/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jonhoo","download_url":"https://codeload.github.com/jonhoo/throttled-reader/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248465313,"owners_count":21108244,"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-13T20:57:05.841Z","updated_at":"2025-04-11T19:07:00.836Z","avatar_url":"https://github.com/jonhoo.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# throttled-reader\n\n[![Crates.io](https://img.shields.io/crates/v/throttled-reader.svg)](https://crates.io/crates/throttled-reader)\n[![Documentation](https://docs.rs/throttled-reader/badge.svg)](https://docs.rs/throttled-reader/)\n[![Build Status](https://travis-ci.org/jonhoo/throttled-reader.svg?branch=master)](https://travis-ci.org/jonhoo/throttled-reader)\n\nThis crate provides `ThrottledReader`, a proxy-type for `io::Read` that limits how many times\nthe underlying reader can be read from. If the read budget is exceeded,\n`io::ErrorKind::WouldBlock` is returned instead. This type can be useful to enforce fairness\nwhen reading from many (potentially asynchronous) input streams with highly varying load. If\none stream always has data available, a worker may continue consuming its input forever,\nneglecting the other stream.\n\n## Examples\n\n```rust\nlet mut buf = [0];\nlet mut stream = ThrottledReader::new(io::empty());\n\n// initially no limit\nassert!(stream.read(\u0026mut buf).is_ok());\nassert!(stream.read(\u0026mut buf).is_ok());\n\n// set a limit\nstream.set_limit(2);\nassert!(stream.read(\u0026mut buf).is_ok()); // first is allowed through\nassert!(stream.read(\u0026mut buf).is_ok()); // second is also allowed through\n// but now the limit is reached, and the underlying stream is no longer accessible\nassert_eq!(\n    stream.read(\u0026mut buf).unwrap_err().kind(),\n    io::ErrorKind::WouldBlock\n);\n\n// we can then unthrottle it again after checking other streams\nstream.unthrottle();\nassert!(stream.read(\u0026mut buf).is_ok());\nassert!(stream.read(\u0026mut buf).is_ok());\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjonhoo%2Fthrottled-reader","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjonhoo%2Fthrottled-reader","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjonhoo%2Fthrottled-reader/lists"}