Sequential
By default, Aqua code is executed line by line, sequentially.

Contract

  • Data from the first line is available on the second line
  • A second line will be executed only if the first line succeeded
  • If any line failed, then the whole block is failed
  • If all lines succeeded, then the whole block is succeeded
1
f <- first() -- first line
2
second(f) -- second line
Copied!
A block of code is any number of lines on the same indentation level or deeper.

Sequential operations

call arrow

Any runnable piece of code in Aqua is an arrow from its domain to the codomain.
1
-- Call a function
2
foo()
3
​
4
-- Call a function that returns smth, assign results to a variable
5
x <- foo()
6
​
7
-- Call an ability function
8
y <- Peer.identify()
9
​
10
-- Pass an argument
11
z <- Op.identity(y)
Copied!
When you write <-, this means not just "assign results of the function on the right to variable on the left". It means that all the effects are executed: service may change state, the topology may be shifted. But you end up being (semantically) on the same peer where you have called the arrow.

on

on denotes the peer where the code must be executed. on is handled sequentially, and the code inside is executed line by line by default.
1
func foo():
2
-- Will be executed where `foo` was executed
3
bar()
4
​
5
-- Move to another peer
6
on another_peer:
7
-- To call bar, we need to leave the peer where we were and get to another_peer
8
-- It's done automagically
9
bar()
10
​
11
on third_peer via relay:
12
-- This is executed on third_peer
13
-- But we denote that to get to third_peer and to leave third_peer
14
-- an additional hop is needed: get to relay, then to peer
15
bar()
16
​
17
-- Will be executed in the `foo` call site again
18
-- To get from the previous `bar`, compiler will add a hop to relay
19
bar()
Copied!
See more in the Topology section.