Skip to content

Commit

Permalink
Merge pull request #3 from libp2p/feat/interface
Browse files Browse the repository at this point in the history
generify options.
  • Loading branch information
magik6k authored Jun 19, 2019
2 parents e4cf01b + 1831efd commit 45c47c8
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions p2p/host/eventbus/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ var closeEmit struct{}
type subSettings struct {
forcedType reflect.Type
}
type SubOption func(*subSettings) error

type SubOption func(interface{}) error

// ForceSubType is a Subscribe option which overrides the type to which
// the subscription will be done. Note that the evtType must be assignable
Expand All @@ -29,7 +30,8 @@ type SubOption func(*subSettings) error
// cancel, err := eventbus.Subscribe(eventCh, event.ForceSubType(new(Event)))
// [...]
func ForceSubType(evtType interface{}) SubOption {
return func(s *subSettings) error {
return func(settings interface{}) error {
s := settings.(*subSettings)
typ := reflect.TypeOf(evtType)
if typ.Kind() != reflect.Ptr {
return errors.New("ForceSubType called with non-pointer type")
Expand All @@ -42,7 +44,7 @@ func ForceSubType(evtType interface{}) SubOption {
type emitterSettings struct {
makeStateful bool
}
type EmitterOption func(*emitterSettings)
type EmitterOption func(interface{}) error

// Stateful is an Emitter option which makes makes the eventbus channel
// 'remember' last event sent, and when a new subscriber joins the
Expand Down

0 comments on commit 45c47c8

Please sign in to comment.