Ï€-calculus has a notion of the repetitive process: !P = P | !P. That means, you can always fork a new P process if you need it.
In Aqua, two operations correspond to it: you can call a service function (it's just available when it's needed), and you can use for loop to iterate on collections.
for expression
In short, for looks like the following:
xs: []stringfor x <- xs: y <- foo(x)-- x and y are not accessible there, you can even redefine themx <- bar()y <- baz()
Contract
Iterations of for loop are executed sequentially by default.
Variables defined inside for loop are not available outside.
for loop's code has access to all variables above.
xs: []string
for x <- xs try:
-- Will stop trying once foo succeeds
foo(x)
xs: []string
for x <- xs par:
on x:
foo()
-- Once the fastest x succeeds, execution continues
-- If you want to make the subsequent execution independent from for,
-- mark it with par, e.g.:
par continueWithBaz()
xs: []string
return: *string
-- can be par, try, or nothing
for x <- xs par:
on x:
return <- foo()
-- Wait for 6 fastest results -- see Join behavior
baz(return!5, return)