add timeout to wait()

added timeout to wait()