mirror of
https://github.com/getAlby/lndhub.go.git
synced 2025-12-20 14:14:47 +01:00
background routine: add context cancel support
This commit is contained in:
@@ -271,6 +271,7 @@ func (suite *WebSocketTestSuite) TestWebSocketMissingInvoice() {
|
|||||||
func (suite *WebSocketTestSuite) TearDownSuite() {
|
func (suite *WebSocketTestSuite) TearDownSuite() {
|
||||||
suite.invoiceUpdateSubCancelFn()
|
suite.invoiceUpdateSubCancelFn()
|
||||||
suite.websocketServer.Close()
|
suite.websocketServer.Close()
|
||||||
|
clearTable(suite.service, "invoices")
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestWebSocketSuite(t *testing.T) {
|
func TestWebSocketSuite(t *testing.T) {
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"database/sql"
|
"database/sql"
|
||||||
"encoding/hex"
|
"encoding/hex"
|
||||||
|
"fmt"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@@ -122,6 +123,10 @@ func (svc *LndhubService) InvoiceUpdateSubscription(ctx context.Context) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
for {
|
for {
|
||||||
|
select {
|
||||||
|
case <-ctx.Done():
|
||||||
|
return fmt.Errorf("Context was canceled")
|
||||||
|
default:
|
||||||
// receive the next invoice update
|
// receive the next invoice update
|
||||||
rawInvoice, err := invoiceSubscriptionStream.Recv()
|
rawInvoice, err := invoiceSubscriptionStream.Recv()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -150,4 +155,5 @@ func (svc *LndhubService) InvoiceUpdateSubscription(ctx context.Context) error {
|
|||||||
sentry.CaptureException(processingError)
|
sentry.CaptureException(processingError)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user