Skip to content

v0.3.0

Compare
Choose a tag to compare
@jkongie jkongie released this 28 Jun 10:51
· 138 commits to main since this release
41d697f
  • Use context to cancel a blocking Dial.

    // With timeout
      ctx := context.Background()
      ctx, cancel := context.WithTimeout(ctx, 5*time.Second)
      defer cancel()
      conn, err := wsrpc.DialWithContext(ctx, "127.0.0.1:1338",
      	wsrpc.WithTransportCreds(privKey, serverPubKey),
      	wsrpc.WithBlock(),
      )
    
    // Manual cancel
    ctx := context.Background()
      ctx, cancel := context.WithCancel(ctx)
      go func() {
      conn, err := wsrpc.DialWithContext(ctx, "127.0.0.1:1338",
      	wsrpc.WithTransportCreds(privKey, serverPubKey),
      	wsrpc.WithBlock(),
      )}()
    
    // Something causes the need to cancel.
    cancel()
    
  • Subscribe to a notification channel to get updates when a client connection is
    established or dropped. You can then retrieve the latest list of keys

      go func() {
      	for {
      		notifyCh := s.GetConnectionNotifyChan()
      		<-notifyCh
    
      		fmt.Println("Connected to:", s.GetConnectedPeerPublicKeys())
      	}
      }()