[CLOSED] How can i make tokio event loop?

I saw a post[1] of making asynchronous chat server with nginx like architecture. But libraries used there are outdated. So i want to make something similar but using tokio. In that post autor made mio eventloop, but i can't see any events in tokio, even tought tokio described as event driven library. How can i implement/use eventloop similar way to original post, nginx like?

[1]Rust in Detail: Writing Scalable Chat Service from Scratch)

I wrote a simple chat server with Tokio. You can find it here: https://github.com/darksonn/telnet-chat

Other than that, I recommend checking out the Tokio tutorial on the Tokio website.


Thank you for prompt reply. I'll definetely take a look at your project. So the idea is to use channels in lieu of event polls?

UPD: I mean, is it possibly fully replace event mechanic by a channels in functional aspect?

The thing to understand is that Tokio isn't an event loop as you might understand it from other languages. It uses the async/await feature which lets you write imperative code, and then Rust automatically converts it into code using an invisible event loop.

If you wanted to access the event loop directly, you would need to use mio instead, and you wouldn't be able to use async/await.


Does async/await distribute the load on the cores evenly? I am just afraid of the imbalance of this approach.

If you use the multi-threaded Tokio runtime, then it will perform work stealing to ensure that all cores have work.


Thank you a lot, that's all i needed to know

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.