Read the Room: Measuring Air Quality with Rust and Elixir

Поделиться
HTML-код
  • Опубликовано: 17 ноя 2024

Комментарии • 30

  • @conradtaylor29
    @conradtaylor29 2 месяца назад +2

    Great example of combining Elixir with Rust!!!!!

  • @nullzeon
    @nullzeon 3 месяца назад +3

    I didn't even notice this was a 17 min video, felt too short! A follow up would be soo good

  • @aviagarwal3011
    @aviagarwal3011 3 месяца назад +4

    More rustler and zigler content please!

  • @caelim3524
    @caelim3524 3 месяца назад +2

    Even if a server for a website might not use this specifically, the ability to run native code to interact outside the confines of a browser then use the browser as a tool to create frontends is super powerful. This reminds me a lot of mopidy which is a music playing server that has several web based frontend plugins available.
    This also could allow more performant processing of certain data by offloading that to another more performant language while still handling all the web stuff in elixir so you can, for example, combine the speed of rust and serve those results easily to thousands of concurrent connections in real time.

  • @akaibukai
    @akaibukai 3 месяца назад +2

    Very cool demo! Thanks for sharing.
    One more sign I should start learning Rust! (Also heard Zig with Zigler being a good option)

    • @CodeAndStuff
      @CodeAndStuff  3 месяца назад

      Thanks for the feedback! I wish I knew Zig (and will probably be looking into it soon) because the integration through the ~Z sigil looks really smooth.

  • @elfenlaid
    @elfenlaid 3 месяца назад +1

    Such a remarkable video, amazing work!

  • @guglielmobartelloni
    @guglielmobartelloni 3 месяца назад +4

    The best elixir content creator

  • @nagyszabolcs9451
    @nagyszabolcs9451 3 месяца назад +1

    This has been a great video! As others said, I really did not notice that 17 minutes have passed.
    The animation are on point, and the fact that there was no music in the background let me properly focus, great work!
    One quick question, did you have a build step for Tailwind, or did you import all of the classes? I usually have some sort of build step in order to not have the huge bundle of all the css classes. (note that I'm not at all familiar with Elixir, I'm asking out of curiosity)

    • @CodeAndStuff
      @CodeAndStuff  3 месяца назад

      Thanks! I’m glad you enjoyed it!
      By default, modern Phoenix apps come with a Tailwind build step by default-no config needed.

  • @aaronfree6796
    @aaronfree6796 3 месяца назад +1

    Love this! A great way to combine the best of both languages.

  • @JP4CK1
    @JP4CK1 3 месяца назад +1

    This was super interesting, thanks for the video!

  • @FrancoBugnano
    @FrancoBugnano 3 месяца назад +1

    Great tutorial. The only thing that might be worth mentioning is that a NIF should not run for more than 1millisecond, ore else bad things happen (it messes with the Erlang scheduler). Given that the Rust library is async, I suspect it's because its functions take more than 1ms to run, so a better approach would be, from the Rust side, to start a new thread with the Tokio runtime that's running continuously, and use something like crossbeam_channel to communicate between the NIF and the Tokio thread. The NIF for reading the sensor would only send the request to read to the Tokio thread and return immediately. When the Tokio thread has the result, it can send a message directly to Elixir. From the Elixir side, you call the NIF, and then use a receive block to wait for the message passed by the Tokio thread. I know that this complicates things a lot, but it would be the more correct way of doing NIFs

    • @CodeAndStuff
      @CodeAndStuff  3 месяца назад +1

      Totally makes sense. In this case I did end up marking the functions as dirty IO in the project pushed on GitHub to avoid harming the scheduler. A crossbeam channel / receive sounds really interesting though, maybe for a future rustler video!

  • @nozdrenkov
    @nozdrenkov 3 месяца назад +3

    Loving your videos! Please keep it up!!

  • @icrayay
    @icrayay 3 месяца назад +1

    Great explanation and extraordinary editing skills for _only_ 1k subs! Keep going

  • @alanmccann
    @alanmccann 3 месяца назад +2

    Great video! Thanks!

  • @tyalt1
    @tyalt1 3 месяца назад

    Awesome example of NIFs and LiveView!
    I'd love to see this taken one step further, where you use Nerves to run the sensor code and web server on a Raspberry Pi or something, because this feels like an IoT project.

    • @CodeAndStuff
      @CodeAndStuff  3 месяца назад +1

      Thanks! It definitely crossed my mind, I just don’t have a modern Raspberry Pi (yet!)

  • @dhonydev
    @dhonydev 3 месяца назад +2

    Thanks for the content 😊

  • @ericdescourtis6242
    @ericdescourtis6242 3 месяца назад +1

    Great demo but as a next step could you show us how to do this without a blocking call? What if we want the data without waiting?

    • @CodeAndStuff
      @CodeAndStuff  3 месяца назад

      I think there’s some unavoidable time spent communicating with the device (which is why I introduced the GenServer as a managed cache), but I might explore an approach like @FrancoBugnano described that uses a receive block. Either approach will take around the same amount of time to get data, but the latter would be more efficient on the beam side.

  • @justafreak15able
    @justafreak15able 3 месяца назад +2

    I don't understand both rust and elixer but this was amazing. The sensor and FFI was cool but I was stunned by how easly you could create a websocket enabled site with elixer. It's websockt right or is it a SSE?

    • @CodeAndStuff
      @CodeAndStuff  3 месяца назад

      Phoenix LiveView uses Websockets with an automatic fallback to long polling on failure. Definitely a superpower

  • @pixelriegel
    @pixelriegel 11 часов назад

    Does a package like Rustler exist but for golang?

  • @vishalontheline
    @vishalontheline 3 месяца назад +1

    Great tutorial! =)

  • @joemartinez3218
    @joemartinez3218 2 месяца назад +1

    We not gonna talk about how it's 80 degrees in his office!

    • @CodeAndStuff
      @CodeAndStuff  2 месяца назад +1

      Haha, it’s hard to record with the AC background noise and it was like 110 degrees F outside!

  • @XnetRoidPL
    @XnetRoidPL 3 месяца назад

    Very cool!
    I know this is out of scope for this tutorial, but tokio runtime should probably be stored in a lazy evaluated static?
    Not sure if FFI will cause problems here

    • @CodeAndStuff
      @CodeAndStuff  3 месяца назад

      Thanks! I didn’t want to get too deep into more complicated things like lazy static but you’re totally right. I think the way NIFs are loaded would be fine with a static, but I’ve never tried it