lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


I’m in a project where I have a server config (luasockets, copas, etc), but also need to use an external library that uses a lot of async calls/multithreading/callbacks. How would I get the callbacks back into lua (running on the interpreter, not embedded) without running into thread issues?

 

My server config will mostly be waiting on a luasockets select statement for some socket action, if I would store the callbacks in a queue and then would go polling I would;

1) introduce either delays if using longer timeouts on select, or

2) I would keep the select timeout small but that would result in more of a busy-wait situation.

 

One solution I figured could be to have the callback results be stored in a queue (C side), and then fire a TCP packet on a luasocket, this would make the select-call return and indicate that there are callback results to collect from the queue. Would work but feels like an ugly workaround.

 

Is there a common practice for solving this type of issue?

 

Any help is greatly appreciated!

 

Thijs