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));
(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.
- What the heck is the event loop anyway? | Philip Roberts | JSConf EU
- https://rohitpaulk.com/articles/redis-3
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)
Top comments (0)