title: How to call a closure with a delay in Rust? Is tokio::timer::Delay a proper tool for making asynchronous callbacks?
body: <p>How to call a closure with a delay in Rust? Is <code>tokio::timer::Delay</code> a proper tool for making asynchronous callbacks?</p>
  <p>My code:</p>
  <pre class="lang-rust prettyprint-override"><code>pub struct Object1 {
      k1: i32,
  }
  
  //
  
  impl Object1 {
      pub fn new() -&gt; Object1 {
          Object1 { k1: 13 }
      }
  }
  
  //
  
  fn main() {
      let object1: Box&lt;Object1&gt; = Box::new(Object1::new());
  
      callback_call_1(Box::new(|| {
          println!(&quot;{:?}&quot;, object1.k1);
      }));
  }
  
  //
  
  fn callback_call_1&lt;F&gt;(mut callback1: F)
  where
      F: FnMut(),
  {
      println!(&quot;inside callback_call_1&quot;);
      callback1();
      /* how to call callback1 with delay 1 second, not blocking the thread?
      is it possible to call the callback1 in the same thread?
      is it possible to reach similar behavior setTimeout from JavaScript has?
      */
  }
  
  </code></pre>
  <p>Here is <a href="https://play.rust-lang.org/?version=stable&amp;mode=debug&amp;edition=2018&amp;gist=862e7baafc70026a684ffd3e3807460c" rel="nofollow noreferrer">playground</a>.</p>