feat(embassy-sync): Add try_take() to signal

This commit is contained in:
Rasmus Melchior Jacobsen 2023-12-20 08:37:15 +01:00
parent 97e919ea64
commit f9d0daad80

View File

@ -111,6 +111,17 @@ where
poll_fn(move |cx| self.poll_wait(cx))
}
/// non-blocking method to try and take the signal value.
pub fn try_take(&self) -> Option<T> {
self.state.lock(|cell| {
let state = cell.replace(State::None);
match state {
State::Signaled(res) => Some(res),
_ => None,
}
})
}
/// non-blocking method to check whether this signal has been signaled.
pub fn signaled(&self) -> bool {
self.state.lock(|cell| {