Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: Use cleanup manager to unsubscribe
Browse files Browse the repository at this point in the history
bgins committed Nov 8, 2024
1 parent 7ece065 commit 3fa2960
Showing 6 changed files with 7 additions and 35 deletions.
7 changes: 1 addition & 6 deletions pkg/web3/events_jobcreator.go
Original file line number Diff line number Diff line change
@@ -49,12 +49,7 @@ func (s *JobCreatorEventChannels) Start(
if err != nil {
return err
}

defer func() {
if jobAddedSub != nil {
jobAddedSub.Unsubscribe()
}
}()
cm.RegisterCallback(unsubscribeSub(jobAddedSub))

for {
select {
7 changes: 1 addition & 6 deletions pkg/web3/events_mediation.go
Original file line number Diff line number Diff line change
@@ -49,12 +49,7 @@ func (m *MediationEventChannels) Start(
if err != nil {
return err
}

defer func() {
if mediationRequestedSub != nil {
mediationRequestedSub.Unsubscribe()
}
}()
cm.RegisterCallback(unsubscribeSub(mediationRequestedSub))

for {
select {
6 changes: 1 addition & 5 deletions pkg/web3/events_payments.go
Original file line number Diff line number Diff line change
@@ -49,12 +49,8 @@ func (p *PaymentEventChannels) Start(
if err != nil {
return err
}
cm.RegisterCallback(unsubscribeSub(paymentSub))

defer func() {
if paymentSub != nil {
paymentSub.Unsubscribe()
}
}()
for {
select {
case <-ctx.Done():
8 changes: 2 additions & 6 deletions pkg/web3/events_pow.go
Original file line number Diff line number Diff line change
@@ -3,6 +3,7 @@ package web3
import (
"context"
"fmt"

"github.com/ethereum/go-ethereum/accounts/abi/bind"
"github.com/ethereum/go-ethereum/event"
"github.com/lilypad-tech/lilypad/pkg/system"
@@ -49,12 +50,7 @@ func (s *PowEventChannels) Start(
if err != nil {
return err
}

defer func() {
if newPowRoundSub != nil {
newPowRoundSub.Unsubscribe()
}
}()
cm.RegisterCallback(unsubscribeSub(newPowRoundSub))

for {
select {
7 changes: 1 addition & 6 deletions pkg/web3/events_storage.go
Original file line number Diff line number Diff line change
@@ -49,12 +49,7 @@ func (s *StorageEventChannels) Start(
if err != nil {
return err
}

defer func() {
if dealStateChangeSub != nil {
dealStateChangeSub.Unsubscribe()
}
}()
cm.RegisterCallback(unsubscribeSub(dealStateChangeSub))

for {
select {
7 changes: 1 addition & 6 deletions pkg/web3/events_token.go
Original file line number Diff line number Diff line change
@@ -52,12 +52,7 @@ func (t *TokenEventChannels) Start(
if err != nil {
return err
}

defer func() {
if transferSub != nil {
transferSub.Unsubscribe()
}
}()
cm.RegisterCallback(unsubscribeSub(transferSub))

for {
select {

0 comments on commit 3fa2960

Please sign in to comment.