Re: [go-nuts] Implementing an EventBus in Go

2019-03-10 Thread Kasun Vithanage
Hi were you talking about something like this? I used channels over callbacks. I quickly prototyped it. Is this approach better or we have to do improvements? package main import ( "fmt" "math/rand" "sync" "time" ) type Data struct { data interface{} topic string } type ChannelSlice []chan Da

Re: [go-nuts] Implementing an EventBus in Go

2019-03-10 Thread Kasun Vithanage
Thanks, I was wondering whether we can replace callbacks with channels. The same way it is used in here, instead of calling a function we can also send the data to a channel associated with the receiver. like var subs = make(map[string] []chan string) func publish(topic string, data string) { g

Re: [go-nuts] Implementing an EventBus in Go

2019-03-10 Thread Randall O'Reilly
for reference, here is a very basic Qt-style signal / slot style subscribe / publish model in Go, just using a map of receivers and their receiver callback functions: https://github.com/goki/ki/blob/master/ki/signal.go - Randy > On Mar 10, 2019, at 11:07 PM, Kasun Vithanage wrote: > > Yes, wh

Re: [go-nuts] Implementing an EventBus in Go

2019-03-10 Thread Kasun Vithanage
My intention is to implement it myself. I was wondering whether to go plain old callback way where a subscriber can subscribe to a topic and callback is fired when a topic is updated. I was really wondering how to utilize go's channels to improve this pattern and gain performance. My final inte

Re: [go-nuts] Implementing an EventBus in Go

2019-03-10 Thread Kasun Vithanage
Yes, when a publisher publish for a topic it should be routed to all subscribers to that topic :) On Monday, March 11, 2019 at 10:28:17 AM UTC+5:30, Burak Serdar wrote: > > On Sun, Mar 10, 2019 at 10:41 PM Kasun Vithanage > wrote: > > > > Hi all, > > > > I've experience implementing event bu

Re: [go-nuts] Implementing an EventBus in Go

2019-03-10 Thread Marcin Romaszewicz
Channels are producer/consumer queues, they don't handle one to many broadcasting, you'd need one channel per subscriber then you'd queue the message to each of them. In my opinion, they work more nicely than callbacks, since your handler can run in its own execution context, and not in the callbac

Re: [go-nuts] Implementing an EventBus in Go

2019-03-10 Thread Burak Serdar
On Sun, Mar 10, 2019 at 10:41 PM Kasun Vithanage wrote: > > Hi all, > > I've experience implementing event buses in Java. > In Java, I used a singleton where I can register callbacks to methods and > fire event from a publisher(maybe from another thread) and propagate it to > subscribers. > > In

[go-nuts] Implementing an EventBus in Go

2019-03-10 Thread Kasun Vithanage
Hi all, I've experience implementing event buses in Java. In Java, I used a singleton where I can register callbacks to methods and fire event from a publisher(maybe from another thread) and propagate it to subscribers. In Go what would be the best pattern to implement a pub/sub event bus? Ar