Skip to content
This repository has been archived by the owner on May 26, 2022. It is now read-only.

Commit

Permalink
Merge pull request #61 from libp2p/event-bus-option
Browse files Browse the repository at this point in the history
add a WithEventBus constructor option
  • Loading branch information
marten-seemann committed Dec 2, 2021
2 parents efb3b08 + b582752 commit 311a313
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions blank.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ type BlankHost struct {
}

type config struct {
cmgr connmgr.ConnManager
cmgr connmgr.ConnManager
eventBus event.Bus
}

type Option = func(cfg *config)
Expand All @@ -48,6 +49,12 @@ func WithConnectionManager(cmgr connmgr.ConnManager) Option {
}
}

func WithEventBus(eventBus event.Bus) Option {
return func(cfg *config) {
cfg.eventBus = eventBus
}
}

func NewBlankHost(n network.Network, options ...Option) *BlankHost {
cfg := config{
cmgr: &connmgr.NullConnMgr{},
Expand All @@ -57,10 +64,12 @@ func NewBlankHost(n network.Network, options ...Option) *BlankHost {
}

bh := &BlankHost{
n: n,
cmgr: cfg.cmgr,
mux: mstream.NewMultistreamMuxer(),
eventbus: eventbus.NewBus(),
n: n,
cmgr: cfg.cmgr,
mux: mstream.NewMultistreamMuxer(),
}
if bh.eventbus == nil {
bh.eventbus = eventbus.NewBus()
}

// subscribe the connection manager to network notifications (has no effect with NullConnMgr)
Expand Down

0 comments on commit 311a313

Please sign in to comment.