I’ve been trying to wrap my head around concurrency for several months now and I have an idea. At least it could become a good primer and maybe even a piece of documentation.
The goal is to write a program that is a simple chat server: a client writes a string to a socket and all the clients receive it. There are however some additional limitations.
- The program should exit clean on SIGINT (we’d like to illustrate signal handling).
- The program should not raise any exceptions during normal operation and the clean shutdown path.
- The client should be able to kick any client (closing connections from server side).
- The client should be able to set a read timeout for any client (fiber management).
- The client should be able to pipe a string to an external program run by the server (child processes).
- The program should reap all its child processes.
- No sleep loops (the purpose is the async mindset).
- The program shouldn’t avoid static analysis (e.g. pipes instead of channels).
Bonus points: the program should allow intraspection, for example listing its fibers to the client on command.
Nice and easy, right?