mirror of
https://github.com/libp2p/go-eventbus.git
synced 2024-12-26 23:30:08 +08:00
0976d4b358
License: MIT Signed-off-by: Jakub Sztandera <kubuxu@protonmail.ch>
33 lines
756 B
Go
33 lines
756 B
Go
package eventbus
|
|
|
|
type subSettings struct {
|
|
buffer int
|
|
}
|
|
|
|
var subSettingsDefault = subSettings{
|
|
buffer: 16,
|
|
}
|
|
|
|
func BufSize(n int) func(interface{}) error {
|
|
return func(s interface{}) error {
|
|
s.(*subSettings).buffer = n
|
|
return nil
|
|
}
|
|
}
|
|
|
|
type emitterSettings struct {
|
|
makeStateful bool
|
|
}
|
|
|
|
// 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
|
|
func Stateful(s interface{}) error {
|
|
s.(*emitterSettings).makeStateful = true
|
|
return nil
|
|
}
|