I’m trying to implement a delay based retry. As far as I know there is nothing in ic_cdk_timers that allows for this so here is my implementation. Are there any big holes? Is this dangerous AF, especially if it’s called multiple times?
You may want to check out what is done in GitHub - PanIndustrial-Org/timerTool: A timer management tool for motoko. for async. Obviously it’s motoko, but it should translate well enough to rust. There is a safety timer that is set with each async call and a timeout is applied. There are hooks for both handling trapped errors and eventual timeouts by the client allowing you to retry if you’d like. Currently this makes handling asyncs synchronous per timerTool instance, but you could instantiate a new one for each process.
Hi @frederico02, Looks like that code will run an infinite number of attempts as long as the function f returns errors. The attempt variable is being set to 0 on every timer-run.
let _ = __retry_with_attempts_delay(max_attempts, current_attempt + 1, delay_duration, f).await;
You are never getting the recursive result, right ?
Meaning with your code, if you retry at least one time you’ll return Error even if one nested called worked, or am i missing something?
Yes that’s right. The original question was about retrying after some delay with a timer. A timer doesn’t have a return value and you can’t await timer. A timer can’t return a value, but a timer can update your canister’s state. If you want to wait for the retries within the current-call-context you can remove the timer and return the result.