Add refresh_func parameter to wait_for()

This adds the option to pass a `refresh_func` function called **after** every unsuccessful try.