This is a very naive question, please forgive my ignorance if I use the wrong terms.
If I have a series of instructions as in the snippet,
bool methodComplete = false;
methodComplete = doSomeMethod(someParam, etcParam); //long & complex method that returns true
if (methodComplete)
doSomeOtherMethod();
will the method doSomeMethod()
finish its execution before if (methodComplete)
is evaluated?
Or is this a case for an asynchronous pattern if I want to guarantee it is completed?
The language specifications define how a program will effectively behave from the point of the user/programmer. So, yes, you can assume that the program behaves as that:
doSomeMethod
methodComplete
That said, some optimizations might result in code executed ahead, see Speculative execution.
will the method
doSomeMethod()
finished executing beforeif (methodComplete)
is evaluated?
Yes*.
or is this a case for an asynchronous pattern if I want to guarantee it has completed?
Only if you are doing parallel computing.
*)It can get to be a no if your code is executing in parallel..
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With