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:
Max Brunsfeld 2022-03-04 13:47:06 -08:00
parent 1982a8c27d
commit c61a1bd659
3 changed files with 66 additions and 33 deletions

View file

@ -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::*;