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
Scala-gopher is open source (license is Apache2); binaries are available from the maven-central repository.
16
18
17
19
## Overview
@@ -107,7 +109,9 @@ val s = goScope{
107
109
108
110
## Channels
109
111
110
-
Inside go blocks, you can look on the channel as on classic blocked queue with fixed size. Different execution flows can exchange messages via channels.
112
+
Channels are used for asynchronous communication between execution flows.
113
+
114
+
When using channel inside *go* block, you can look at one as on classic blocked queue with fixed size with methods read and write:
111
115
112
116
113
117
val channel = gopherApi.makeChannel[Int];
@@ -136,8 +140,11 @@ Also, channels can be closed. After this attempt to write will cause throwing 'C
136
140
137
141
Note, closing channels is not mandatory; unreachable channels are garbage-collected regardless of they are closed or not.
138
142
139
-
Also, you can use only 'Input' or 'Output' interfaces, where appropriative read/write operations are defined.
140
-
For an input, exists usual collection functions, like `map`, `zip`, `takeN`. Scala Iterable can be represented as `channels.Input` via method `gopherApi.iterableInput`. Also, we can use Scala futures as channels, which produce one value and then closes. For obtaining such input use `gopherApi.futureInput`.
143
+
144
+
Channels can be buffered and unbuffered. In a unbuffered channel, write return control to the caller after another side actually will start processing; buffered channel force provider to wait only if internal channel buffer is full.
145
+
146
+
Also, you can use only `Input` or `Output` interfaces, where appropriative read/write operations are defined.
147
+
For `Input`, exists usual collection functions, like `map`, `zip`, `takeN`, `fold` ... etc. Scala Iterable can be represented as `channels.Input` via method `gopherApi.iterableInput`. Also, we can use Scala futures as channels, which produce one value and then closes. For obtaining such input use `gopherApi.futureInput`.
141
148
142
149
`|` (i.e. or) operator used for merged inputs, i.e. `(x|y).read` will read a value from channel x or y when one will be available.
143
150
@@ -154,7 +161,7 @@ will return two inputs, where reading from `inReady` will return the same as rea
154
161
Also, note that you can provide own Input and Output implementations by implementing callback `cbread` and `cbwrite` methods.
155
162
156
163
157
-
## Select loops
164
+
## Select loops and folds
158
165
159
166
'select statement' is somewhat similar to Unix 'select' syscall:
160
167
from a set of blocking operations select one who is ready to input/output and run it.
@@ -216,6 +223,34 @@ val consumer = gopherApi.select.forever{
216
223
Await.ready(consumer, 5.second)
217
224
~~~
218
225
226
+
Combination from variable and select loop better modeled with help 'fold over select'>
0 commit comments