Cycle consumption recording problem

When I recorded the consumption of cycles, I found a very strange problem.
Motoko is a reactor model, should there be no concurrency problems? Or maybe it appears?

This is my demo code,
Execute after I deploy the code
If I click call once and wait for the result to execute, the result is what I want

But when I clicked it multiple times quickly, the result was the same as the picture.
There are fewer cycles before the execution of the loop than after the execution of the loop

1 Like

@nomeata @stephenandrews help me?

When I use async await to get the data and hashmap to store the sh. A more amazing problem occurs, I can’t even get my cycles。

Yeah await drops atomicity, so you need to handle that in your code
This is my demo without async await

@avi yeah looks good I think if you move the demo’s await before Array.append

I modified it, but it still appeared.

In my case, I quickly clicked call 10 times within 3 seconds.

1 Like

This is expected. You lose atomicity after await. So you cannot assume the global state is the same when the async calls reply back. See Joachim’s blog post about inter-canister calls.

Is motoko not single threaded?