Separate issue; implications of the above still sinking in for me:
On Discord (Discord), this scenario:
Say in the case someone calls function X while A is executing.
A is executing, and inside it there are calls to B and C:
- await B
// here someone else calls X, not from inside A
- await C
return from A
Would that run A, B, C, return A, enter X or
would it run A, B, X, C, return from A
got this answer:
An await is an abstraction over a callback being executed later. What order stuff runs in depends on a lot of factors, especially subnets. But in the most pessimistic execution case, the latter; nothing prevents calling another method before the callback runs.
So if we bring that back to the timer, and executing time-sensitive processes, we might have:
Timer is executing, and inside it there are async calls to B, C, D, some inter-canister, some to other canisters (asume all canisters are well-behaved and don’t delay return), some of which themselves call other canisters with async / await:
- await B // maybe a intercanister call to a function that itself awaits a call in another canister
// at this point someone else, not from inside Timer and from outside the canister, calls function X in our canister
- await C // again may include async calls to other canisters within it
return / exit from timer
Doesn’t the Discord answer say that X could be executed before C, and therefore before Timer finishes processing, and therefore before the time-critical process is finalised?
If so, what approach or flow can be used to guarantee that the complete body of timer is executed first, including its async calls, or otherwise guarantee that the time-critical process in the body of timer is indeed finalised on time such that the system (in this case a defi protocol), which depends on that time-critical execution, won’t malfunction?
I sort of created a control flow system that sets a variable to false when certain things are being processed, and then checks that condition before executing most of the body of the rest of the canister’s functions, but
(a) is this the only way (and even a way that works) and
(b) ideally there would be a way doesn’t even attempt executing other functions, partly because the fact that other functions are being kept from entering the if statement where most of the body is only guarantees that those things don’t happen, rather than guaranteeing that the complete body of timer does happen (on time).
I expect there may be misconceptions in my framing.