Skip to content

Commit

Permalink
examples: use context
Browse files Browse the repository at this point in the history
  • Loading branch information
magiconair committed Jan 27, 2022
1 parent 3b9868f commit 73ac88c
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions examples/crypto/crypto.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ import (
"strings"
"syscall"

"golang.org/x/crypto/ssh/terminal"

"github.com/gopcua/opcua"
"github.com/gopcua/opcua/debug"
"github.com/gopcua/opcua/errors"
"github.com/gopcua/opcua/ua"

"golang.org/x/crypto/ssh/terminal"
)

var (
Expand Down Expand Up @@ -68,7 +68,7 @@ func main() {
defer c.CloseSessionWithContext(ctx)

// Use our connection (read the server's time)
v, err := c.Node(ua.NewNumericNodeID(0, 2258)).Value()
v, err := c.Node(ua.NewNumericNodeID(0, 2258)).ValueWithContext(ctx)
if err != nil {
log.Fatal(err)
}
Expand All @@ -79,7 +79,7 @@ func main() {
}

// Detach our session and try re-establish it on a different secure channel
s, err := c.DetachSession()
s, err := c.DetachSessionWithContext(ctx)
if err != nil {
log.Fatalf("Error detaching session: %s", err)
}
Expand All @@ -88,16 +88,16 @@ func main() {

// Create a channel only and do not activate it automatically
d.Dial(ctx)
defer d.Close()
defer d.CloseWithContext(ctx)

// Activate the previous session on the new channel
err = d.ActivateSession(s)
err = d.ActivateSessionWithContext(ctx, s)
if err != nil {
log.Fatalf("Error reactivating session: %s", err)
}

// Read the time again to prove our session is still OK
v, err = d.Node(ua.NewNumericNodeID(0, 2258)).Value()
v, err = d.Node(ua.NewNumericNodeID(0, 2258)).ValueWithContext(ctx)
if err != nil {
log.Fatal(err)
}
Expand Down

0 comments on commit 73ac88c

Please sign in to comment.