What's point of timeout?

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
User avatar
Bobble68
Party member
Posts: 160
Joined: Wed Nov 30, 2022 9:16 pm
Contact:

What's point of timeout?

Post by Bobble68 »

Hello there my lövelies!

I've been messing around with lua-enet recently, and I've been slowly adapting the initial example on the wiki into my own program - however, I'm confused about host:service() - I found that setting a timeout value makes it wait for incoming events, but leaving it as nil will make it not wait but still recieve events. The example uses a timeout of 100, but I found my own program worked much better leaving it nil.

In short, what's the point of timeout? If it does turn out to be important, I'll look into multithreading so it doesn't disturb the framerate in the way it currently does.
Dragon
User avatar
pgimeno
Party member
Posts: 3551
Joined: Sun Oct 18, 2015 2:58 pm

Re: What's point of timeout?

Post by pgimeno »

I haven't looked into lua-enet, but if that timeout is what I think it is (i.e. internally passed to a select() call) then it's intended for pausing the thread until either something is received, or the timeout expires, whichever comes first. It's useful in the case of a multithreaded application with a thread dedicated entirely to listening, or in the case of an application which can afford pausing while communicating through a socket. That pause makes the thread not suck CPU resources during the wait; if it was in a tight loop constantly monitoring whether there's data ready, it would consume CPU, but this way, the OS can let other threads/processes run while that one is waiting.

In your case, if you want it in the main thread, you probably don't need a timeout; you can simply use love.update() to check if there's something waiting and that works just fine. The Löve gameloop already takes care of not sucking CPU time, by waiting for Vsync or 1ms. So, nil should be OK.
Post Reply

Who is online

Users browsing this forum: No registered users and 55 guests