Skip to content

Commit

Permalink
client: add missing WithContext methods
Browse files Browse the repository at this point in the history
  • Loading branch information
magiconair committed Jan 27, 2022
1 parent 4dee16b commit aaca6d8
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
10 changes: 9 additions & 1 deletion client.go
Original file line number Diff line number Diff line change
Expand Up @@ -552,12 +552,20 @@ func (c *Client) Dial(ctx context.Context) error {
}

// Close closes the session and the secure channel.
//
// Note: Starting with v0.5 this method will require a context
// and the corresponding XXXWithContext(ctx) method will be removed.
func (c *Client) Close() error {
return c.CloseWithContext(context.Background())
}

// Note: Starting with v0.5 this method is superseded by the non 'WithContext' method.
func (c *Client) CloseWithContext(ctx context.Context) error {
stats.Client().Add("Close", 1)

// try to close the session but ignore any error
// so that we close the underlying channel and connection.
c.CloseSession()
c.CloseSessionWithContext(ctx)
c.setState(Closed)

if c.mcancel != nil {
Expand Down
10 changes: 9 additions & 1 deletion subscription.go
Original file line number Diff line number Diff line change
Expand Up @@ -289,13 +289,21 @@ func (s *Subscription) notify(ctx context.Context, data *PublishNotificationData
}

// Stats returns a diagnostic struct with metadata about the current subscription
//
// Note: Starting with v0.5 this method will require a context
// and the corresponding XXXWithContext(ctx) method will be removed.
func (s *Subscription) Stats() (*ua.SubscriptionDiagnosticsDataType, error) {
return s.StatsWithContext(context.Background())
}

// Note: Starting with v0.5 this method is superseded by the non 'WithContext' method.
func (s *Subscription) StatsWithContext(ctx context.Context) (*ua.SubscriptionDiagnosticsDataType, error) {
// TODO(kung-foo): once browsing feature is merged, attempt to get direct access to the
// diagnostics node. for example, Prosys lists them like:
// i=2290/ns=1;g=918ee6f4-2d25-4506-980d-e659441c166d
// maybe cache the nodeid to speed up future stats queries
node := s.c.Node(ua.NewNumericNodeID(0, id.Server_ServerDiagnostics_SubscriptionDiagnosticsArray))
v, err := node.Value()
v, err := node.ValueWithContext(ctx)
if err != nil {
return nil, err
}
Expand Down

0 comments on commit aaca6d8

Please sign in to comment.