cancel context

This commit is contained in:
callebtc
2022-07-08 22:13:33 +02:00
parent cfe1cd0c60
commit b124478caf
3 changed files with 6 additions and 3 deletions

View File

@@ -13,7 +13,6 @@ import (
func (app *app) dispatchChannelAcceptor(ctx context.Context) {
client := app.client
// wait group for channel acceptor
defer ctx.Value(ctxKeyWaitGroup).(*sync.WaitGroup).Done()
// get the lnd grpc connection

View File

@@ -5,6 +5,7 @@ import (
"errors"
"fmt"
"strconv"
"sync"
"time"
"github.com/lightningnetwork/lnd/lnrpc"
@@ -14,6 +15,8 @@ import (
)
func (app *app) dispatchHTLCAcceptor(ctx context.Context) {
// wait group for channel acceptor
defer ctx.Value(ctxKeyWaitGroup).(*sync.WaitGroup).Done()
conn := app.conn
router := routerrpc.NewRouterClient(conn)

View File

@@ -49,6 +49,7 @@ func getClientConnection(ctx context.Context) (*grpc.ClientConn, error) {
grpc.WithBlock(),
grpc.WithPerRPCCredentials(cred),
}
log.Infof("Connecting to LND...")
conn, err := grpc.DialContext(ctx, Configuration.Host, opts...)
if err != nil {
return nil, err
@@ -75,12 +76,12 @@ func main() {
app.myPubkey, err = app.getMyPubkey(ctx)
if err != nil {
log.Errorf("Could not get my pubkey: %s", err)
return
continue
}
var wg sync.WaitGroup
ctx = context.WithValue(ctx, ctxKeyWaitGroup, &wg)
wg.Add(1)
wg.Add(2)
// channel acceptor
go app.dispatchChannelAcceptor(ctx)