mirror of
https://github.com/fluencelabs/aqua-book
synced 2024-12-04 23:30:18 +00:00
GitBook: [master] 3 pages modified
This commit is contained in:
parent
f27d59874e
commit
44cfd39420
@ -21,6 +21,7 @@
|
||||
* [Services](language/expressions/services.md)
|
||||
* [Type definitions](language/expressions/type-definitions.md)
|
||||
* [Overrideable constants](language/expressions/overrideable-constants.md)
|
||||
* [CRDT Streams](language/crdt-streams.md)
|
||||
* [Abilities & Services](language/abilities-and-services.md)
|
||||
* [Imports & exports](language/statements-1.md)
|
||||
* [Aqua Patterns](aqua-patterns.md)
|
||||
|
2
language/crdt-streams.md
Normal file
2
language/crdt-streams.md
Normal file
@ -0,0 +1,2 @@
|
||||
# CRDT Streams
|
||||
|
@ -135,9 +135,93 @@ func bar():
|
||||
|
||||
Visibility scopes follows the contracts of execution flow.
|
||||
|
||||
By default, everything defined textually above is available below. With some exceptions.
|
||||
|
||||
Functions have isolated scopes:
|
||||
|
||||
```text
|
||||
func foo():
|
||||
a = 5
|
||||
|
||||
func bar():
|
||||
-- a is not defined in this function scope
|
||||
a = 7
|
||||
foo() -- a inside fo is 5
|
||||
```
|
||||
|
||||
[For loop](operators/iterative.md#export-data-from-for) does not export anything from it:
|
||||
|
||||
```text
|
||||
func foo():
|
||||
x = 5
|
||||
for y <- ys:
|
||||
-- Can use what was defined above
|
||||
z <- bar(x)
|
||||
|
||||
-- z is not defined in scope
|
||||
z = 7
|
||||
```
|
||||
|
||||
[Parallel](operators/parallel.md#join-behavior) branches have [no access](https://github.com/fluencelabs/aqua/issues/90) to each other's data:
|
||||
|
||||
```text
|
||||
-- This will deadlock, as foo branch of execution will
|
||||
-- never send x to a parallel bar branch
|
||||
x <- foo()
|
||||
par y <- bar(x)
|
||||
|
||||
-- After par is executed, all the can be used
|
||||
baz(x, y)
|
||||
```
|
||||
|
||||
Recovery branches in [conditional flow](operators/conditional.md) has no access to the main branch. Main branch exports values, recovery branch does not:
|
||||
|
||||
```text
|
||||
try:
|
||||
x <- foo()
|
||||
otherwise:
|
||||
-- this is not possible – will fail
|
||||
bar(x)
|
||||
y <- baz()
|
||||
|
||||
-- y is not available below
|
||||
willFail(y)
|
||||
|
||||
```
|
||||
|
||||
### Streams as literals
|
||||
|
||||
Stream is a special data that allows many writes. It worth a dedicated article.
|
||||
Stream is a special data that allows many writes. It has [a dedicated article](crdt-streams.md).
|
||||
|
||||
Here we just explain how to initiate streams and use them as empty collection literals. Refer to conditional return.
|
||||
To use a stream, you need to initiate it at first:
|
||||
|
||||
```text
|
||||
-- Appendable collection of strings, empty
|
||||
resp: *string
|
||||
|
||||
-- Write strings to resp in parallel
|
||||
resp <- foo()
|
||||
par resp <- bar()
|
||||
|
||||
for x <- xs:
|
||||
-- Write to a stream that's defined above
|
||||
resp <- baz()
|
||||
|
||||
try:
|
||||
resp <- baz()
|
||||
otherwise:
|
||||
on "other peer":
|
||||
resp <- baz()
|
||||
|
||||
-- Now resp can be used in place of arrays and optional values
|
||||
-- assume fn: []string -> ()
|
||||
fn(resp)
|
||||
|
||||
-- Can call fn with empty stream: you can use it
|
||||
-- to construct empty values of any collection types
|
||||
nilString: *string
|
||||
fn(nilString)
|
||||
```
|
||||
|
||||
One of the most frequently used patterns for streams is [Conditional return](operators/conditional.md#conditional-return).
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user