The Crystal Programming Language Forum

Concurrency challenge

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.

  1. The program should exit clean on SIGINT (we’d like to illustrate signal handling).
  2. The program should not raise any exceptions during normal operation and the clean shutdown path.
  3. The client should be able to kick any client (closing connections from server side).
  4. The client should be able to set a read timeout for any client (fiber management).
  5. The client should be able to pipe a string to an external program run by the server (child processes).
  6. The program should reap all its child processes.
  7. No sleep loops (the purpose is the async mindset).
  8. 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?