Skip to content

Commit

Permalink
fix(DataStore): Add 'weak self' to prevent retain cycles in OutgoingM…
Browse files Browse the repository at this point in the history
…utationQueue (#3429)

* fix(DataStore): Add 'weak self' to prevent retain cycles

* update to use optional binding directly
  • Loading branch information
lawmicha authored Dec 20, 2023
1 parent a55e899 commit 006e045
Showing 1 changed file with 10 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,8 @@ final class OutgoingMutationQueue: OutgoingMutationQueueBehavior {
self.stateMachineSink = self.stateMachine
.$state
.sink { [weak self] newState in
guard let self = self else {
return
}
guard let self else { return }

self.log.verbose("New state: \(newState)")
self.mutationDispatchQueue.async {
self.respond(to: newState)
Expand Down Expand Up @@ -138,7 +137,9 @@ final class OutgoingMutationQueue: OutgoingMutationQueueBehavior {
self.api = api
self.reconciliationQueue = reconciliationQueue

queryMutationEventsFromStorage {
queryMutationEventsFromStorage { [weak self] in
guard let self = self else { return }

self.operationQueue.isSuspended = false
// State machine notification to ".receivedSubscription" will be handled in `receive(subscription:)`
mutationEventPublisher.publisher.subscribe(self)
Expand Down Expand Up @@ -319,7 +320,8 @@ final class OutgoingMutationQueue: OutgoingMutationQueueBehavior {
self.dispatchOutboxMutationProcessedEvent(mutationEvent: mutationEvent,
mutationSync: mutationSync)
}
self.queryMutationEventsFromStorage {
self.queryMutationEventsFromStorage { [weak self] in
guard let self else { return }
self.stateMachine.notify(action: .processedEvent)
}
}
Expand All @@ -333,7 +335,9 @@ final class OutgoingMutationQueue: OutgoingMutationQueueBehavior {
predicate: predicate,
sort: nil,
paginationInput: nil,
eagerLoad: true) { result in
eagerLoad: true) { [weak self] result in
guard let self else { return }

switch result {
case .success(let events):
self.dispatchOutboxStatusEvent(isEmpty: events.isEmpty)
Expand Down

0 comments on commit 006e045

Please sign in to comment.