waitFor function.