Updated task wait() method to raise timeout error