Skip to content

Commit 4959ecc

Browse files
hlbarberHarry Barber
and
Harry Barber
authored
Add strong/weak pointer counts to Shared (#2346)
Co-authored-by: Harry Barber <[email protected]>
1 parent 6acaa81 commit 4959ecc

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

Diff for: futures-util/src/future/future/shared.rs

+26
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,32 @@ where
126126
}
127127
None
128128
}
129+
130+
/// Gets the number of strong pointers to this allocation.
131+
///
132+
/// Returns [`None`] if it has already been polled to completion.
133+
///
134+
/// # Safety
135+
///
136+
/// This method by itself is safe, but using it correctly requires extra care. Another thread
137+
/// can change the strong count at any time, including potentially between calling this method
138+
/// and acting on the result.
139+
pub fn strong_count(&self) -> Option<usize> {
140+
self.inner.as_ref().map(|arc| Arc::strong_count(arc))
141+
}
142+
143+
/// Gets the number of weak pointers to this allocation.
144+
///
145+
/// Returns [`None`] if it has already been polled to completion.
146+
///
147+
/// # Safety
148+
///
149+
/// This method by itself is safe, but using it correctly requires extra care. Another thread
150+
/// can change the weak count at any time, including potentially between calling this method
151+
/// and acting on the result.
152+
pub fn weak_count(&self) -> Option<usize> {
153+
self.inner.as_ref().map(|arc| Arc::weak_count(arc))
154+
}
129155
}
130156

131157
impl<Fut> Inner<Fut>

0 commit comments

Comments
 (0)