Initial implementation of wait_for().