You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
var int ret = 0;
par/or do
await async (ret) do
// calculates fat of 10
var int fat = 1;
var int i = 10;
loop do
if i == 0 then
break;
end
fat = fat * i;
i = i - 1;
end
ret = fat;
end;
with
await 1s; // kill the async if it takes long
ret = 0;
end
escape ret;
and set var int i = 1;. I expected factorial of 1 to be computed faster than 1s, but surprisingly result was 0.
How can this be explained?
The text was updated successfully, but these errors were encountered:
The behavior is correct. Unfortunately, the example/explanation is mostly incomplete.
To get the expected behavior, you need to split the emit 1s, into multiple emit 100ms.
Since the examples are running on the server in "simulation mode", all input is artificial and has no relation with the real world.
If your program says emit 1s, Céu will just assume that happened and simulate that 1s elapsed, so it will not have time to advance the async trail.
When you split the simulation into multiple steps of 100ms, each time Céu will also advance the async trail.
(As an alternative, you could also use an async/thread trail to get real parallelism, but it's not supported in the online tutorial.)
Oh, ok. Then I propose to change that example, so there are 10 emit 1s; in "input", and await 10s in code. So, reducing factorial number would actually work.
I've modified code (copying here original one)
and set
var int i = 1;
. I expected factorial of 1 to be computed faster than 1s, but surprisingly result was 0.How can this be explained?
The text was updated successfully, but these errors were encountered: