1. 19
  1.  

  2. 2

    I believe that the following snip of code:

    #[tokio::main]
    async fn main() -> Result<(), std::io::Error> {
        let mut interval = time::interval(Duration::from_secs(1));
        loop {
            interval.tick().await;
            Command::new("date").spawn()?.await?;
        }
    }
    

    can be changed to use the never type as of rust 1.41:

    #[tokio::main]
    async fn main() -> Result<!, std::io::Error> {
        let mut interval = time::interval(Duration::from_secs(1));
        loop {
            interval.tick().await;
            Command::new("date").spawn()?.await?;
        }
    }
    

    I say this because it makes the answer to the question that follows, “why is there no Ok(()) returned at the end”, much more obvious

    1. 1

      I’m very excited for the never type to land in stable Rust!

    2. 2

      Author is using a std::sync::Mutex, but I think should use a tokio::sync::Mutex, otherwise this can and eventually will lock up the runtime (-thread) and all other futures in the queue.

      (And mentioning atomics could help some people here, as you get lock free shared state.) Otherwise this looks promising for my upcoming futures-0.1 to async/await transition.

      1. 2

        Good point. I wasn’t paying much attention to the Mutex bit, since it was an intermediate step towards my real goal of LocalSet. But the way I wrote it is definitely wrong. Thanks!