Add callback for connects and reconnects.

This commit is contained in:
Josh Rickmar 2014-06-04 14:58:31 -05:00
parent 8e624b20a9
commit 793e66c785
2 changed files with 18 additions and 4 deletions

View file

@ -855,7 +855,15 @@ func (c *Client) start() {
c.wg.Add(1) c.wg.Add(1)
go c.sendPostHandler() go c.sendPostHandler()
} else { } else {
c.wg.Add(2) c.wg.Add(3)
go func() {
if c.ntfnHandlers != nil {
if c.ntfnHandlers.OnClientConnected != nil {
c.ntfnHandlers.OnClientConnected()
}
}
c.wg.Done()
}()
go c.wsInHandler() go c.wsInHandler()
go c.wsOutHandler() go c.wsOutHandler()
} }

View file

@ -79,10 +79,16 @@ func newNilFutureResult() chan *futureResult {
// notifications are effectively ignored until their handlers are set to a // notifications are effectively ignored until their handlers are set to a
// concrete callback. // concrete callback.
// //
// NOTE: These handlers must NOT directly call any blocking calls on the client // NOTE: Unless otherwise documented, these handlers must NOT directly call any
// instance since the input reader goroutine blocks until the callback has // blocking calls on the client instance since the input reader goroutine blocks
// completed. Doing so will result in a deadlock situation. // until the callback has completed. Doing so will result in a deadlock
// situation.
type NotificationHandlers struct { type NotificationHandlers struct {
// OnClientConnected is invoked when the client connects or reconnects
// to the RPC server. This callback is run async with the rest of the
// notification handlers, and is safe for blocking client requests.
OnClientConnected func()
// OnBlockConnected is invoked when a block is connected to the longest // OnBlockConnected is invoked when a block is connected to the longest
// (best) chain. It will only be invoked if a preceding call to // (best) chain. It will only be invoked if a preceding call to
// NotifyBlocks has been made to register for the notification and the // NotifyBlocks has been made to register for the notification and the