First implementation of simple event loop.