We need to wait until all EventMachine items in flight are complete before we
allow the process to terminate or some of them might not happen. So when the
process wants to exit, wait until the EM thread is done. Use next_tick to make
sure our stop command only happens when the EM queue is next clear.