Is it possible to have an async heartbeat function?

The use case is that I would like to call async functions from heartbeat.

It is possible to change update (and I presume query) to async and thereby allow async functions to be made from them. Condvar wait not supported

However the heartbeat function appears to be sync. When I try to add async to heartbeat function definition, I get the following error:

The invocation to the wallet call forward method failed with the error: An error happened during the call: 5: Wasm module of canister sbzkb-zqaaa-aaaaa-aaaiq-cai is not valid: Wasm module has an invalid function signature. Expected return type for ā€˜canister_heartbeatā€™, got [I32]

2 Likes

Rust or Motoko?

(This question is too short for the forum)

In rust.

(The answer is too short for forum)

Just based on your error message, is your heartbeat function returning an i32? Try it without a return type.

The heart beat function is not returning a i32

if I have the function without async,

#[export_name = ā€œcanister_heartbeatā€]
fn heartbeat_fn () {
ic_cdk::print(ā€œniceā€);
}

works fine.

However with async, not so.

#[export_name = ā€œcanister_heartbeatā€]
async fn heartbeat_fn () {
ic_cdk::print(ā€œniceā€);
}
ā€¦
Installing code for canister dfx_hello, with canister_id tzq7c-xqaaa-aaaaa-aaamq-cai
The invocation to the wallet call forward method failed with the error: An error happened during the call: 5: Wasm module of canister tzq7c-xqaaa-aaaaa-aaamq-cai is not valid: Wasm module has an invalid function signature. Expected return type for ā€˜canister_heartbeatā€™, got [I32].