What is the generally accepted way to implement the main loop of a server that needs to wait on a heterogeneous set of events? That is the server should wait (not busywait) until one of the following occurs:
- new socket connection
- data available on an existing socket
- OS signal
- third-party library callbacks
I think you’re thinking in terms of a C paradigm with a single thread, nonblocking I/O, and a select() call.
You can manage to write something like that in Haskell, but Haskell has much more to offer:
I recommend you fork a new thread for every separate point of contact with the outside world, and keep everything coordinated with STM.