For the owlkettle package (a declarative gtk wrapper) in nim I am researching how one could implement multi-threading "properly".
For that I am looking into how one would setup a client-serer architecture generally.
I know nim is able to run multi-threaded when compiled with --threads:on (or on nim 2.0 by default), so this should be possible. This minimal example showcases a mechanism called "channels", but how do I turn this into a more client-server based example where both threads keep going until I stop it?
That just requires a small while-loop on both ends.
The following example is a modification of the one linked above. One "frontend" thread reads in user input from the terminal and sends it to the "backend" thread which can do things with it.
Note that you could also use an object-variant instead of a string (so
Channel[YourMessageVariant]) to allow for sending different kind of messages.Also as a sidenote, the following example will have 3 threads running: