2019-06-19 23:55:25 +08:00
|
|
|
package eventbus
|
2019-06-13 10:23:03 +08:00
|
|
|
|
2019-06-19 20:22:10 +08:00
|
|
|
type subSettings struct {
|
2019-06-22 00:50:36 +08:00
|
|
|
buffer int
|
2019-06-17 00:15:35 +08:00
|
|
|
}
|
2019-06-19 21:08:16 +08:00
|
|
|
|
2019-06-22 00:50:36 +08:00
|
|
|
func BufSize(n int) func(interface{}) error {
|
|
|
|
return func(s interface{}) error {
|
|
|
|
s.(*subSettings).buffer = n
|
2019-06-17 00:15:35 +08:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
2019-06-13 16:04:12 +08:00
|
|
|
|
2019-06-19 20:22:10 +08:00
|
|
|
type emitterSettings struct {
|
2019-06-17 03:42:47 +08:00
|
|
|
makeStateful bool
|
|
|
|
}
|
2019-06-13 16:04:12 +08:00
|
|
|
|
2019-06-19 20:13:48 +08:00
|
|
|
// 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
|
2019-06-19 21:36:31 +08:00
|
|
|
func Stateful(s interface{}) error {
|
|
|
|
s.(*emitterSettings).makeStateful = true
|
|
|
|
return nil
|
2019-06-17 03:42:47 +08:00
|
|
|
}
|