opts.go 750 Bytes
Newer Older
1
package eventbus
Łukasz Magiera's avatar
Łukasz Magiera committed
2

Łukasz Magiera's avatar
Łukasz Magiera committed
3
type subSettings struct {
Łukasz Magiera's avatar
Łukasz Magiera committed
4
	buffer int
Łukasz Magiera's avatar
Łukasz Magiera committed
5
}
Raúl Kripalani's avatar
Raúl Kripalani committed
6

Jakub Sztandera's avatar
Jakub Sztandera committed
7 8 9 10
var subSettingsDefault = subSettings{
	buffer: 16,
}

Łukasz Magiera's avatar
Łukasz Magiera committed
11 12 13
func BufSize(n int) func(interface{}) error {
	return func(s interface{}) error {
		s.(*subSettings).buffer = n
Łukasz Magiera's avatar
Łukasz Magiera committed
14 15 16
		return nil
	}
}
17

Łukasz Magiera's avatar
Łukasz Magiera committed
18
type emitterSettings struct {
Łukasz Magiera's avatar
Łukasz Magiera committed
19 20
	makeStateful bool
}
21

Jun10ng's avatar
Jun10ng committed
22
// Stateful is an Emitter option which makes the eventbus channel
Łukasz Magiera's avatar
Łukasz Magiera committed
23 24 25 26 27 28
// 'remember' last event sent, and when a new subscriber joins the
// bus, the remembered event is immediately sent to the subscription
// channel.
//
// This allows to provide state tracking for dynamic systems, and/or
// allows new subscribers to verify that there are Emitters on the channel
Łukasz Magiera's avatar
Łukasz Magiera committed
29 30 31
func Stateful(s interface{}) error {
	s.(*emitterSettings).makeStateful = true
	return nil
Łukasz Magiera's avatar
Łukasz Magiera committed
32
}