Implement Wait with timeout