atrium_common/types/
throttled.rs1use std::sync::Arc;
2
3pub trait Throttleable<P>
4where
5 Self: std::marker::Sized,
6{
7 fn throttled(self) -> Throttled<Self, P>;
8}
9
10impl<P, T> Throttleable<P> for T
11where
12 P: Default,
13{
14 fn throttled(self) -> Throttled<Self, P> {
15 Throttled::new(self)
16 }
17}
18
19pub struct Throttled<T, P> {
20 pub inner: T,
21 pub pending: Arc<P>,
22}
23
24impl<T, P> Throttled<T, P>
25where
26 P: Default,
27{
28 pub fn new(inner: T) -> Self {
29 Self { inner, pending: Arc::new(P::default()) }
30 }
31}