Closed samuell closed 9 years ago
Hi @samuell!
There are basically 2 approaches to this.
The first approach is reactive and queue-based, it requires you to provide both OnInPort1()
and OnInPort2()
handlers, make a internal buffer to queue incoming data until there is a complete pair. I guess you get the idea.
The second approach is writing a classical active FBP component like this:
// An active Looper component in classical FBP style
type Add2Ports struct {
Component
In1 <-chan int
In2 <-chan int
Out chan<- int
}
func (c *counter) Loop() {
for {
// First read from input one
in1 := <- c.In1
// Then read from input two
in2 := <- c.In2
// Then do something useful
c.Out <- in1 + in2
}
}
The loop is run in its own goroutine which is blocked every time it needs to wait for incoming data on one of the ports. You can also use non-zero connection buffers to get better performance.
Thanks much, @trustmaster for the info! Looks good!
@samuell You can see an example of the internal queueing approach from our antha cross compiler as well. For example: https://github.com/antha-lang/antha/blob/master/reference/reference.go showing the compiler output for an element that allows individual wiring of the inputs, but requires all parameters to have arrived before it fires.
Many thanks @seanward, will have a look!
Hello Vlad!
Great to see work going on, on GoFlow! :+1:
I started looking at it again for some recent use cases, but had one question: How would I implement a component that waits for two inputs, before it does its job? The default way seems to be to implement a
On<InportName>()
function, but so I would need something that doesOn<Inport1><Inport2>()
:) ... but I'm sure there is a better way for this?Best // Samuel