Stop and close event loop gracefully.