Hi, semi-beginner with NIM, like it a lot but still need to get used to rather new way, for me, to structure the programs. I'm attempting to port to NIM an application written in Python. The application receives inputs both from a GUI and from a socket whose messages are used to update the GUI status (widgets colors, labels etc).
Here's where I need a bit of advice on how to proceed:
Any GUI library (now I'm tinkering with nimx, but the pattern is general of course) has its own event loop. But also receiving input from a socket requires a runForever() if you're using an asyncSocket, and even (I think) if you create a Thread and wait for info appearing on a channel. I can see no way forward and I'm sure I'm missing something or making wrong assumptions. What is the common pattern to make the two event loops coexist, or how to get rid of the one under my control, the network inflow related event loop ?
Thank you very much for any advice on this.
BTW, since I'm here I'll pinpoint a nice, OpenGL based, GUI library here https://github.com/mitsuba-renderer/nanogui I'm not involved with the project, just a user. It is nice looking, well documented, comes with compiled python bindings which work like a charm with nimpy. I managed to port to nim/nimpy the whole example1.py which showcases 100% of the widgets (couldn't test only the shaders functions, they use numpy and I still struggle with that part of nim/nimpy syntax)
Nanogui also poses to me the same event loop question...
For an example how I did see https://github.com/nim-lang/Nim/blob/devel/tools/downloader.nim
Esp this section:
pollingMainLoop((proc (timeout: int) =
if hasPendingOperations(): asyncdispatch.poll(timeout)), 10)
But beware: This code is old and was never used in production.
receiving input from a socket requires a runForever()
runForever() is just an infinite while loop running poll(). Just make sure to run poll(<timeout>) along your GUI event loop and you should be fine :)
thank you.
Indeed I do the network stuff (parsing, filtering downloads etc) in a separate program, using async/await, and after the processing I send the gui relevant info to the GUI app via another socket.
I'd prefer to listen also this "GUI" socket in a thread, that's what I do in Python, but there I can call methods of objects outside the thread...
yes, I RTFM but I really learn only after I crash my nose on the wall :-)
I'll make a poll on the channel.