At first you must receive gopherApi as Akka extension:
import gopher._
.....
val gopherApi = Gopher(actorSystem)
Then you can use CPS channels with blocling operations inside go clauses:
val channel = gopherApi.makeChannel[Long]
val n = 10000val producer = go {
@volatilevar(x,y) = (0L,1L)
for( s <- gopherApi.select.forever) {
case z: channel.write if (z==x) =>
x = y
y = x+z
if (x > n) {
channel.close
implicitly[FlowTermination[Unit]].doExit()
}
}
}
val consumer = for((c,i) <- channel.zip(1 to n)) {
Console.println(s"fib(${i})=${c}")
}
Await.ready(consumer, 10 seconds)
and defer/recover in go/goScope
goScope{
val f = openFile(myFileName)
defer{
if (! recover{case ex:FileNotFoundException =>Console.println("invalid fname")}) {
f.close()
}
}
}
Provides scala API for 'go-like' CSP channels.
Overview
see readme for quick introduction.
Usage
At first you must receive gopherApi as Akka extension:
Then you can use CPS channels with blocling operations inside go clauses:
and defer/recover in go/goScope
channels.SelectFactory
channels.SelectorBuilder
channels.Output
channels.Input
channels.Channel
GopherAPI