I try to implement a query function that calls an async function but, I am facing the error “misplaced await”.
I have the feeling I am hitting the limitation described in this post but, hopefully, I am “just” missing something.
Any idea how can I solve this?
import Error "mo:base/Error";
actor Echo {
public query func say(phrase : Text) : async Text {
await check_permission(phrase); // <-- misplaced await
return phrase;
};
private func check_permission(phrase: Text) : async () {
if (phrase == "no") {
throw Error.reject("No permission.");
}
};
};
P.S.: Long story short. I have to transform my shared functions (“getter”) to query in order to improve the performance of the readonly queries of my web app.
On the other side, as we have users, I have implemented a permission check that throw errors if access is not granted. Therefore throw Error.reject which, I think, requires the function to be async.