1. 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!

    1. 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!

      1. 3

        Um, I do not believe the author of this post meant 3rd Amendment. This has nothing to do with quartering troops.

        1. 3
          1. 2

            There’s some discussion in the blog’s comments about how the 3rd Amendment might be relevant, since requiring printers to print these dots has an effect similar to stationing an informant in someone’s home. Seems like a stretch to me though.

            1. 3

              Yeah, that seems completely incongruous with any other reading of the 3rd Amendment.

            2. 1

              The Third Amendment has only ever faced one serious court challenge. A prison in New York had on-site housing for the guards. The guards went on strike, and the state brought the National Guard in to control the prison….and housed the soldiers in the same housing.

              The court found that that the state did violate the Third Amendment, but not itentionally, and that the case did not establish precedent.

            1. 4

              Because the example is so well prepared, I just tried it out and was somewhat surprised that it would not use more than 1 CPU.

              To make it use 4 CPUs on my system I had to compile it with:

              stack ghc --resolver lts-7.14 --install-ghc --package conduit-extra -- --make -threaded echo.hs
              

              And then run it with:

              ./echo +RTS -N4
              

              Then you can see that with every new connection and long input it will use more and more CPU.

              1. 3

                Good point, thank you! I’ve added an update to the blog post about this.

              1. 1

                How do both parties agree upon exchanging data such as binary data, dates, and so on, where there might be multiple valid textual representations? The benefit of a spec is that it constrains the design space on uninteresting problems like data interchange so you can focus on more important things.

                1. 2

                  Standard Microformats are a thing; I’d say this is an easier problem to solve in HTML than in json

                  1. 1

                    To be fair, JSON doesn’t address binary data or dates directly, it would need to be agreed upon by both parties. That seems orthogonal to whether we use JSON or HTML5 as the data serialization format.