Timers API: async function execution

2
closed
verkhohliad
verkhohliad
Posted 3 months ago

Timers API: async function execution #351

Is there a case to make callables async functions provided to timers? If so, can you please show example? For now, for me, it's just ignoring everything in the callable function for the timer that is async.

dfinity-berestovskyy
dfinity-berestovskyy

Try to wrap your async function in ic_cdk::spawn(), i.e.:

async async_fn() {
     call().await;
    ...
}

let _id = timer::set_timer(..., || ic_cdk::spawn(async_fn()));
verkhohliad
verkhohliad
Created 3 months ago

Try to wrap your async function in ic_cdk::spawn(), i.e.:

async async_fn() {
     call().await;
    ...
}

let _id = timer::set_timer(..., || ic_cdk::spawn(async_fn()));

Awesome, it works, thanks. 🙏