This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
thomasbogue's profile picture

Is it possible to have two threads viewing events?

Started by thomasbogue, 10 August 2013 - 11:34 AM
thomasbogue #1
Posted 10 August 2013 - 01:34 PM
Title: Is it possible to have two threads viewing events?
I'm building a GUI API, and I have an event processing loop. But I don't want to step on the toes of the user of my API by grabbing events that they were trying to process. I'd also like to be able to run my event processing loop in a separate thread. Right now I'm filtering pretty severely, but I might like to grab click, touch, and keypress events. Can I do this without preventing the user from having their own event processing loop?
Bubba #2
Posted 10 August 2013 - 01:41 PM
Well you could use os.queueEvent to queue any events that you filter out, but that would mean that you would have to get rid of the loop. ComputerCraft doesn't really have threads, but you can run things in parallel using either the parallel api or coroutines. However, both of these would require a bit of knowledge on the user's part. I personally just have a checkEvent function in your API that allows the user to check clicks and such whenever they want. This would be the easy solution.
thomasbogue #3
Posted 10 August 2013 - 03:43 PM
Thanks. That's much simpler than the ideas I had. Already written into the API.