feat(embassy-sync): Add try_take() to signal
This commit is contained in:
parent
97e919ea64
commit
f9d0daad80
1 changed files with 11 additions and 0 deletions
|
@ -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| {
|
||||
|
|
Loading…
Reference in a new issue