Merge pull request #2328 from rmja/signal-try-take
feat(embassy-sync): Add try_take() to signal
This commit is contained in:
commit
c8eb128a56
@ -111,6 +111,20 @@ 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),
|
||||
state => {
|
||||
cell.set(state);
|
||||
None
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
/// non-blocking method to check whether this signal has been signaled.
|
||||
pub fn signaled(&self) -> bool {
|
||||
self.state.lock(|cell| {
|
||||
|
Loading…
Reference in New Issue
Block a user