Make timer method available on both foreground and background executors
Also, make it return a static future. Co-Authored-By: Nathan Sobo <nathan@zed.dev>
This commit is contained in:
parent
1982a8c27d
commit
c61a1bd659
3 changed files with 66 additions and 33 deletions
|
@ -123,6 +123,18 @@ where
|
|||
}
|
||||
}
|
||||
|
||||
struct Defer<F: FnOnce()>(Option<F>);
|
||||
|
||||
impl<F: FnOnce()> Drop for Defer<F> {
|
||||
fn drop(&mut self) {
|
||||
self.0.take().map(|f| f());
|
||||
}
|
||||
}
|
||||
|
||||
pub fn defer<F: FnOnce()>(f: F) -> impl Drop {
|
||||
Defer(Some(f))
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue