My main concern is around the 3 channels I have between Go 1 and Go 2, because I cannot find anyone use this 3 chan approach, and I'm wondering if I'm making some larger mistake that could be solved a better way.
I have a scenario which I want to get some feedback on.Attached is a drawing modeling my situation. There are 3 go routines representing 3 layers/packages in my application.
1) There's in trigger in Go 1 that initiates a request for some data that is managed by Go 2. It (Go 1) sends a request with a key on reqData chan.2) Go 2 returns a pointer to the data on the data chan.3) Go 1 does some processing/updates to the data based on the trigger mentioned earlier,4) When complete, Go 1 sends a notification to Go 2 saying it's done processing the data,5) Go 2 does some of it's own processing on the data relevant to it's own layer.6) Finally as one of those processing steps, Go 2 notifies Go 3 there was an update to the data by sending it (the updated data) on a chan to Go 3.
My main concern is around the 3 channels I have between Go 1 and Go 2, because I cannot find anyone use this 3 chan approach, and I'm wondering if I'm making some larger mistake that could be solved a better way.
Cheers,Mark
On Sunday, May 31, 2015 at 8:31:40 AM UTC+3, Mark Laczynski wrote:My main concern is around the 3 channels I have between Go 1 and Go 2, because I cannot find anyone use this 3 chan approach, and I'm wondering if I'm making some larger mistake that could be solved a better way.
I am sorry, but it is a bit too abstract to understand.
After goroutine1 has gotten data from goroutine2, goroutine2 is idle until "done"? Then why not merge the two rooutines into one?
--Giulio
On Sunday, 31 May 2015 08:31:40 UTC+3, Mark Laczynski wrote:I have a scenario which I want to get some feedback on.Attached is a drawing modeling my situation. There are 3 go routines representing 3 layers/packages in my application.The proper solution highly depends on what the Go1..Go3 are. so what are they? What are you implementing?1) There's in trigger in Go 1 that initiates a request for some data that is managed by Go 2. It (Go 1) sends a request with a key on reqData chan.2) Go 2 returns a pointer to the data on the data chan.3) Go 1 does some processing/updates to the data based on the trigger mentioned earlier,4) When complete, Go 1 sends a notification to Go 2 saying it's done processing the data,5) Go 2 does some of it's own processing on the data relevant to it's own layer.6) Finally as one of those processing steps, Go 2 notifies Go 3 there was an update to the data by sending it (the updated data) on a chan to Go 3.I would write the interaction piece... e.g.func Interact(A A, B B, C C) error {data, err := B.Request(A.GetParams())if err != nil {return err}err := A.HandleData(data)if err != nil {return err}B.DataHandled(data)C.Notify(data)}And follow design of it from there...By breaking up the interaction into different goroutines/objects/types you are making the interaction harder to understand.
My main concern is around the 3 channels I have between Go 1 and Go 2, because I cannot find anyone use this 3 chan approach, and I'm wondering if I'm making some larger mistake that could be solved a better way.You might be overusing channels.
Cheers,Mark
Go Routine 1 parses a continuous stream. That is its whole responsibility, because there's just a lot of logic in parsing the stream "packets."Go Routine 2 manages and owns the data. So basically this routine is serializing the access to the data, because various parts of the application can be updating/reading from the data.Go Routine 3 is an httpHandler that updates the UI. So Go Routine 2 notifies the UI to update the page with the new data.