lua - Do something while waiting for a blocking action -


I'm trying to write a curse program in Lea (mostly for ease of development before porting it for C for). The user needs to constantly prepare it to send the command, but I also want it to work on other signals, such as the end of the timer. For example, it can be used for blinking indication, if users take too much time, and are receiving messages on the network, then disassemble them.

When I call curses.getch () , the program is waiting to return the data before running the next instructions. If any other event occurs before a key is pressed, the script will not be able to react to it unless nothing is done to change it.

I create curses.halfdelay () to get rid of curses.getch () after a short time so that by calling it again and again It could be done earlier, but it caused the odd errors. I also considered learning to use pthreads, but I do not know where to start, I'm running Linux, and I do not have any problems if the solution does not work on Windows (because I already cursed I'm using).

EDIT: Related details, but I would really like a more general solution that can work with other blocking tasks.

halfdelay () and (more commonly) nodelay () The right choice, in curse space, I can assure you that they work in the normal case. You have to be more specific about your "strange errors".

In the meantime, although this is not a pure curse solution (and will not work with PDCs), people sometimes use select () or to curse Or wait for input from the network socket


Comments