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() {
|
||||
suite.invoiceUpdateSubCancelFn()
|
||||
suite.websocketServer.Close()
|
||||
clearTable(suite.service, "invoices")
|
||||
}
|
||||
|
||||
func TestWebSocketSuite(t *testing.T) {
|
||||
|
||||
@@ -4,6 +4,7 @@ import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"encoding/hex"
|
||||
"fmt"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
@@ -122,6 +123,10 @@ func (svc *LndhubService) InvoiceUpdateSubscription(ctx context.Context) error {
|
||||
return err
|
||||
}
|
||||
for {
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
return fmt.Errorf("Context was canceled")
|
||||
default:
|
||||
// receive the next invoice update
|
||||
rawInvoice, err := invoiceSubscriptionStream.Recv()
|
||||
if err != nil {
|
||||
@@ -150,4 +155,5 @@ func (svc *LndhubService) InvoiceUpdateSubscription(ctx context.Context) error {
|
||||
sentry.CaptureException(processingError)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user