Implemented timeout for waiting events