The unexpected behavior exhibited by the cloud can be explained with something like
Attributes[myevaluateFunction] = {HoldAllComplete};
myevaluateFunction[input___] := WithCleanup[setup[], input, teardown[]];
CloudEvaluate
could very well be using something similar to the code above. Now if you put the module in this evaluation wrapper you get what you initially expected:
```
In[32]:= myevaluateFunction[Module[{}, Return[1]; 2]]
Out[32]= 1
```
I imagine this is the same thing happening with CloudEvaluate[Module[{}, Return[1]; 2]]
or just running the Module
in a cloud notebook: there is some wrapper function that takes your code and passes it to the kernel and then returns the results to you. This extra layer is why the Return[1]
works.
So if you ever find yourself wanting to write code like
Module[{}, Return[1]; 2]
stop and write
Catch[Module[{}, Throw[1]; 2]
instead.