Retry runs the f function until it returns nil but not more than defined in
the attempts argument. After reaching the max attempts, it returns the last
error. The delay argument defines the time between each attempt. If the
context is canceled, the function stops and returns the error.