I’ve built a concurrent FRP framework where different modules, running in their own threads, can publish/subscribe to things from eachother.
Very simplified, each module can have Output[T]
and Input[T]
- these are mutable classes.
Output
and Input
are part of a FRP framework so they can not be shared between modules directly.
Now there’s also a reference to a module: Ref[M <: Module]
.
If module A wants to read/write from module B, it must go via the ref. Instances are never exposed directly.
The way this is done is as following:
trait Module {}
class Ref[M <: Module](ref: ActorRef[ModuleBehavior[M]]) {
def read[T](op: (m: M) => m.Output[T]): Input[Option[T]] = {
ref ! ReadInput(op)
}
}
class A extends Module {
val bRef: Ref[B]
// main part of the question:
bRef.read(_.out) // this will send a message asynchronously to bRef containing the op
}
class B extends Module {
val out: Output[T]
}
As seen when read
is used, I send a path-dependent function in order to pick properties from the instance, since the instance can never be accessed directly.
My question is: is there a way I can do this without a path-dependent function? The current way I’m doing it does not work across processes.