Smooth out threading model.

- Fix many race conditions.
- Simplify shutdown of IrcClient.
- Add a way to wait for event handlers from a Dispatcher.