DEV Community

Yusuf Turhan Papurcu
Yusuf Turhan Papurcu

Posted on

(2/n) Skill issues with event loop

Previously on Avatar....

Move closure

Everything was going cool until the task "Handle concurrent clients" come along. My first intention was just spawning a thread for every request and calling it a day. But while writing I realised I was using this move closure but didn't dig deeper what it exactly means.

std::thread::spawn(move || handle_connection(&mut _stream));
Enter fullscreen mode Exit fullscreen mode

What I did was going directly to Holy Rust Book and searching for the usages of move closure and found it!

(Yes it was my skill issue to realise we are passing the ownership into spawned thread)

I want a different way of handling concurrent clients

Actually it was a different suggestion in the task, it was saying the original redis implementation uses "event loop" so maybe I can try that out too. Also spamming a new thread per request was not satisfying enough for my curiosity on the topic after hearing there is another way to do it.

I started searching videos, blogs and talks about the topic. Here is two that helped me understanding the concept.

The problem was the ruby equivalent of IO.Select was not exists in the Rust std library. But luckily I found it under tokio!

https://github.com/tokio-rs/mio

It even had the simple example I needed! But wait a second, it's not working...

(after digging it for 30m I gave up and moved on)

(but one day in future I will get back and learn how to use mio's event loop implementation)

Image of Timescale

🚀 pgai Vectorizer: SQLAlchemy and LiteLLM Make Vector Search Simple

We built pgai Vectorizer to simplify embedding management for AI applications—without needing a separate database or complex infrastructure. Since launch, developers have created over 3,000 vectorizers on Timescale Cloud, with many more self-hosted.

Read full post →

Top comments (0)

The Most Contextual AI Development Assistant

Pieces.app image

Our centralized storage agent works on-device, unifying various developer tools to proactively capture and enrich useful materials, streamline collaboration, and solve complex problems through a contextual understanding of your unique workflow.

👥 Ideal for solo developers, teams, and cross-company projects

Learn more