Skip to content

Commit

Permalink
refactor: Use cleanup manager to unsubscribe
Browse files Browse the repository at this point in the history
  • Loading branch information
bgins committed Nov 18, 2024
1 parent 0f831c0 commit 9b9ef55
Show file tree
Hide file tree
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
Expand Up @@ -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 {
Expand Down
7 changes: 1 addition & 6 deletions pkg/web3/events_mediation.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
6 changes: 1 addition & 5 deletions pkg/web3/events_payments.go
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down
8 changes: 2 additions & 6 deletions pkg/web3/events_pow.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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 {
Expand Down
7 changes: 1 addition & 6 deletions pkg/web3/events_storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
7 changes: 1 addition & 6 deletions pkg/web3/events_token.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 9b9ef55

Please sign in to comment.