RetryAfter
Sends a request again when the server asks to be asked later, as RFC 8516 §4 has a client do: while the answer is 4.29 Too Many Requests, or 5.03 Service Unavailable with the same meaning for an overload of all clients (RFC 7252 §5.9.3.4), it waits as long as the response's Max-Age says (CoapResponse.retryAfter, 60 seconds without one) and sends the request again, maxAttempts times at most in all.
It never sends earlier than the server asked (RFC 8516 §4: SHOULD NOT): a wait longer than maxWait is not waited out, and the refusal is returned at once for the caller to decide.
The wait is a coroutine
delay, so cancelling the caller ends it, and nothing more is sent.A 4.29 that no security protocol authenticated may be forged to make a client wait (RFC 8516 §5); maxWait bounds what that costs. With message security the client acts only on verified responses (ADR 0008).
Each attempt is a new request, with a new token and Message ID, since the server answered the last one.
val response = RetryAfter(maxWait = 30.seconds).request(client, CoapRequest(CoapCode.GET, CoapUri.parse(uri)))