Skip to content

Commit

Permalink
network: Move client initialization into Init()
Browse files Browse the repository at this point in the history
  • Loading branch information
losfair committed Jul 9, 2018
1 parent 49f64c1 commit ec48a96
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
14 changes: 9 additions & 5 deletions network/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ type PeerClient struct {
incomingReady chan struct{}

jobQueue chan func()
jobExecutorInit sync.Once

closed uint32 // for atomic ops
}
Expand Down Expand Up @@ -63,17 +62,22 @@ func createPeerClient(network *Network, address string) (*PeerClient, error) {
buffer: make([]byte, 0),
buffered: make(chan struct{}),
},

jobQueue: make(chan func(), 128),
}

return client, nil
}

func (c *PeerClient) Submit(job func()) {
c.jobExecutorInit.Do(func() {
c.jobQueue = make(chan func(), 128)
go c.executeJobs()
func (c *PeerClient) Init() {
// Execute 'peer connect' callback for all registered plugins.
c.Network.Plugins.Each(func(plugin PluginInterface) {
plugin.PeerConnect(c)
})
go c.executeJobs()
}

func (c *PeerClient) Submit(job func()) {
// FIXME: This is a hack to prevent closed c.jobQueue from panicking the program.
defer func() {
if err := recover(); err != nil {
Expand Down
5 changes: 1 addition & 4 deletions network/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -284,10 +284,7 @@ func (n *Network) Client(address string) (*PeerClient, error) {
session: session,
})

// Execute 'peer connect' callback for all registered plugins.
n.Plugins.Each(func(plugin PluginInterface) {
plugin.PeerConnect(client)
})
client.Init()

return client, nil
}
Expand Down

0 comments on commit ec48a96

Please sign in to comment.