throwed when channel is closed:
throwed when channel is closed:
Construction Defers: defer/recover is alternative mechanism to exception handling, simular to one in Go language.
Construction Defers: defer/recover is alternative mechanism to exception handling, simular to one in Go language.
We use one hidden in go and goScope construct are transformed to withDefers usage with help of macroses.
It is also possible to use one unsugared (as in next example), but this is a bit verbose.
def parseCsv(fname: String): Either[String, Seq[Seq[Double]]] = withDefer[Either[String,Seq[Seq[Double]]]]{ d => val in = Source.fromFile(fname) d.defer{ var r = d.recover{ case FileNotFoundException => Left("fileNotFound") } if (!r) in.close() d.recover { case ex: Throwable => Left(ex.getMessage) } } val retval:Either[String,Seq[Seq[Double]]] = Right{ for( (line, nLine) <- in.getLines.toSeq zip Stream.from(1) ) yield withDefer[Seq[Double]] { d => line.split(",") map { s=> d.defer{ d.recover{ case ex: NumberFormatException => throw new RuntimeException(s"parse error in line ${nLine} file ${fname} ") } } s.toDouble } }.toSeq } retval }
FlowTermination[-A] - termination of flow.
FlowTermination[-A] - termination of flow.
Inside each block in select loop or select apply (once or forever) we have implicit FlowTermination entity, which we can use for exiting the loop.
select.forever{ case x: info.read => Console.println(s"received from info $x") case x: control.read => implicitly[FlowTermination[Unit]].doExit(()) }
sugar for reading value from future.
Api for providing access to channel and selector interfaces.
Akka extension which provide gopherApi interface
Akka extension which provide gopherApi interface
GopherAPI
Transputer, where dehaviour can be described by selector function
Reusable unit of application structure, which consists from set of input ports, set of output ports and behaviour
Reusable unit of application structure, which consists from set of input ports, set of output ports and behaviour
Transputers can be created as elementary behaviour, descibed by select statement and then can be combined into larger structures
Transputers can be recovered from execeptions (i.e. transputer can be restarted or resume execution) or escalated to parent transputers or root superviser.
mix this trait to ypu transputer for access to akka logging.
Factory object for Akka extension
Factory object for Akka extension
val actorSystem = ActorSystem("myapp") val gopherApi = Gopher(actorSystem)
Core entity is Continuated which provide iteratee-like structure for reading and writing.
Core entity is Continuated which provide iteratee-like structure for reading and writing. Instance of Continuated represent one step of computations and leave in queue inside ChannelProcessor or ChannelActor Selector transform Continuated to executed exclusive with each other within one selector. Also we have IdleDetector which determinate idle selectors and activer appropriative actions.
pseudostatement which can be used inside go/goScope block.
pseudostatement which can be used inside go/goScope block.
starts asyncronics execution of body
in provided execution context.
starts asyncronics execution of body
in provided execution context.
Inside go we can use defer
/recover
clauses and blocked read/write channel operations.
provide access to using defer/recover inside body in the current thread of execution.
can be called only from defer block.
can be called only from defer block. If we in handling exception, try to apply f
to exception and if it's applied - stop panic and return true, otherwise return false.
- partial function for recovering exception.
true if exception was recovered, false otherwise
syntax sugar, for calling Defers.
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.IOChannel
GopherAPI