-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from async-rs/limits
Limits
- Loading branch information
Showing
8 changed files
with
118 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
// use core::pin::Pin; | ||
// use core::task::{Context, Poll}; | ||
|
||
// use std::sync::atomic::{AtomicUsize, Ordering}; | ||
// use std::sync::Arc; | ||
|
||
// use async_std::stream::Stream; | ||
|
||
// /// A stream that has a max concurrency of N. | ||
// pub(crate) struct LimitStream { | ||
// limit: Option<usize>, | ||
// ref_count: Arc<AtomicUsize>, | ||
// } | ||
|
||
// impl LimitStream { | ||
// /// Create a new instance of LimitStream. | ||
// pub(crate) fn new(limit: Option<usize>) -> Self { | ||
// Self { | ||
// limit, | ||
// ref_count: Arc::new(AtomicUsize::new(0)), | ||
// } | ||
// } | ||
// } | ||
|
||
// #[derive(Debug)] | ||
// pub(crate) struct Guard { | ||
// limit: Option<usize>, | ||
// ref_count: Arc<AtomicUsize>, | ||
// } | ||
|
||
// impl Guard { | ||
// fn new(limit: Option<usize>, ref_count: Arc<AtomicUsize>) -> Self { | ||
// Self { limit, ref_count } | ||
// } | ||
// } | ||
|
||
// impl Drop for Guard { | ||
// fn drop(&mut self) { | ||
// if self.limit.is_some() { | ||
// self.ref_count.fetch_sub(1, Ordering::SeqCst); | ||
// } | ||
// } | ||
// } | ||
|
||
// impl Stream for LimitStream { | ||
// type Item = Guard; | ||
|
||
// fn poll_next(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Option<Self::Item>> { | ||
// if self.limit.is_none() { | ||
// let guard = Guard::new(self.limit, self.ref_count.clone()); | ||
// return Poll::Ready(Some(guard)); | ||
// } | ||
// todo!(); | ||
// } | ||
// } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters