mirror of
https://github.com/libp2p/go-eventbus.git
synced 2025-03-13 10:20:10 +08:00
generify options.
This commit is contained in:
parent
04b7ec33de
commit
2ea3b26fbd
@ -10,7 +10,8 @@ var closeEmit struct{}
|
|||||||
type subSettings struct {
|
type subSettings struct {
|
||||||
forcedType reflect.Type
|
forcedType reflect.Type
|
||||||
}
|
}
|
||||||
type SubOption func(*subSettings) error
|
|
||||||
|
type SubOption func(interface{}) error
|
||||||
|
|
||||||
// ForceSubType is a Subscribe option which overrides the type to which
|
// ForceSubType is a Subscribe option which overrides the type to which
|
||||||
// the subscription will be done. Note that the evtType must be assignable
|
// the subscription will be done. Note that the evtType must be assignable
|
||||||
@ -29,7 +30,8 @@ type SubOption func(*subSettings) error
|
|||||||
// cancel, err := eventbus.Subscribe(eventCh, event.ForceSubType(new(Event)))
|
// cancel, err := eventbus.Subscribe(eventCh, event.ForceSubType(new(Event)))
|
||||||
// [...]
|
// [...]
|
||||||
func ForceSubType(evtType interface{}) SubOption {
|
func ForceSubType(evtType interface{}) SubOption {
|
||||||
return func(s *subSettings) error {
|
return func(settings interface{}) error {
|
||||||
|
s := settings.(*subSettings)
|
||||||
typ := reflect.TypeOf(evtType)
|
typ := reflect.TypeOf(evtType)
|
||||||
if typ.Kind() != reflect.Ptr {
|
if typ.Kind() != reflect.Ptr {
|
||||||
return errors.New("ForceSubType called with non-pointer type")
|
return errors.New("ForceSubType called with non-pointer type")
|
||||||
@ -42,7 +44,7 @@ func ForceSubType(evtType interface{}) SubOption {
|
|||||||
type emitterSettings struct {
|
type emitterSettings struct {
|
||||||
makeStateful bool
|
makeStateful bool
|
||||||
}
|
}
|
||||||
type EmitterOption func(*emitterSettings)
|
type EmitterOption func(interface{}) error
|
||||||
|
|
||||||
// Stateful is an Emitter option which makes makes the eventbus channel
|
// Stateful is an Emitter option which makes makes the eventbus channel
|
||||||
// 'remember' last event sent, and when a new subscriber joins the
|
// 'remember' last event sent, and when a new subscriber joins the
|
||||||
|
Loading…
Reference in New Issue
Block a user