Simple event loop implementation.