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

Commit 311a313

Browse files
Merge pull request #61 from libp2p/event-bus-option
add a WithEventBus constructor option
2 parents efb3b08 + b582752 commit 311a313

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

blank.go

+14-5
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ type BlankHost struct {
3737
}
3838

3939
type config struct {
40-
cmgr connmgr.ConnManager
40+
cmgr connmgr.ConnManager
41+
eventBus event.Bus
4142
}
4243

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

52+
func WithEventBus(eventBus event.Bus) Option {
53+
return func(cfg *config) {
54+
cfg.eventBus = eventBus
55+
}
56+
}
57+
5158
func NewBlankHost(n network.Network, options ...Option) *BlankHost {
5259
cfg := config{
5360
cmgr: &connmgr.NullConnMgr{},
@@ -57,10 +64,12 @@ func NewBlankHost(n network.Network, options ...Option) *BlankHost {
5764
}
5865

5966
bh := &BlankHost{
60-
n: n,
61-
cmgr: cfg.cmgr,
62-
mux: mstream.NewMultistreamMuxer(),
63-
eventbus: eventbus.NewBus(),
67+
n: n,
68+
cmgr: cfg.cmgr,
69+
mux: mstream.NewMultistreamMuxer(),
70+
}
71+
if bh.eventbus == nil {
72+
bh.eventbus = eventbus.NewBus()
6473
}
6574

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

0 commit comments

Comments
 (0)