opts.go 702 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

Łukasz Magiera's avatar
Łukasz Magiera committed
7 8 9
func BufSize(n int) func(interface{}) error {
	return func(s interface{}) error {
		s.(*subSettings).buffer = n
Łukasz Magiera's avatar
Łukasz Magiera committed
10 11 12
		return nil
	}
}
13

Łukasz Magiera's avatar
Łukasz Magiera committed
14
type emitterSettings struct {
Łukasz Magiera's avatar
Łukasz Magiera committed
15 16
	makeStateful bool
}
17

Łukasz Magiera's avatar
Łukasz Magiera committed
18 19 20 21 22 23 24
// Stateful is an Emitter option which makes makes the eventbus channel
// '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
25 26 27
func Stateful(s interface{}) error {
	s.(*emitterSettings).makeStateful = true
	return nil
Łukasz Magiera's avatar
Łukasz Magiera committed
28
}