I am trying to make an inter-canister call to call another canister on a successful upgrade. However, it looks like post_upgrade cannot be async. This is the error that I’m seeing:
#[post_upgrade] must be above a function.
expected one of: for, parentheses, fn, unsafe, extern, identifier, ::, <, square brackets, *, &, !, impl, _, lifetime
Maybe use the new timer api to call your function after 1 nano second…it should be the next thing called most of the time. You can add a halt blocker if you need a guarantee.
It does not work. Basically, a timer expects a function that doesn’t return anything whereas an async fuction returns a type of Future. The function has to be an async function because inter canister calls are async and need to be await-ed.
This is the error message I see:
error: expected fn() -> impl Future<Output = ()> {add_one} to be a fn item that returns (), but it returns impl Future<Output = ()>
label: required by a bound introduced by this call
Any other ideas? Curiously, does this workaround work in Motoko?
I think the caveat with this approach based on the threads I linked to is that it doesn’t guarantee that other messages aren’t processed before your timer function is called.
That might be fine for this use case depending on what you want to do.