Skip to content

PurchasesOrchestrator: replaced manual Lock with Atomic#1664

Merged
NachoSoto merged 1 commit into
mainfrom
purchases-orchestrator-atomic
Jun 7, 2022
Merged

PurchasesOrchestrator: replaced manual Lock with Atomic#1664
NachoSoto merged 1 commit into
mainfrom
purchases-orchestrator-atomic

Conversation

@NachoSoto

Copy link
Copy Markdown
Contributor

See #983. This is less error-prone as it's impossible to have deadlocks, or to access the data without locking (like we were doing in some cases).
Also, this approach has 2 separate locks for each property, so unrelated accesses won't lock each other now.

@NachoSoto NachoSoto requested a review from a team June 7, 2022 18:05
@NachoSoto NachoSoto force-pushed the purchases-orchestrator-atomic branch from 86c2abb to 2ed8c36 Compare June 7, 2022 19:15
See #983. This is less error-prone as it's impossible to have deadlocks, or to access the data without locking (like we were doing in some cases).
Also, this approach has 2 separate locks for each property, so unrelated accesses won't lock each other now.

@taquitos taquitos left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I THINK there's a change here you should make, but let me know what you think.

delegate.readyForPromotedProduct(storeProduct) { completion in
self.purchaseCompleteCallbacksByProductID[product.productIdentifier] = completion
self.purchaseCompleteCallbacksByProductID.modify { $0[product.productIdentifier] = completion }
storeKitWrapper.add(payment)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I kinda think it makes sense to add this in to the .modify block since that guarantees the same behavior we had with the lock.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The thing is this is an @escaping block, so the outside lock was likely getting unlocked before this was even modified. Does that make sense?

So the access to purchaseCompleteCallbacksByProductID wasn't protected. I do see that maybe the intent is that the whole thing was, and therefore maybe storeKitWrapper.add(payment) could be inside now. But considering that was missed, and therefore this is the same behavior, maybe this makes more sense?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ahhh, yeah. Makes sense.

@NachoSoto NachoSoto merged commit ade5015 into main Jun 7, 2022
@NachoSoto NachoSoto deleted the purchases-orchestrator-atomic branch June 7, 2022 22:09
@NachoSoto NachoSoto mentioned this pull request Jun 7, 2022
NachoSoto added a commit that referenced this pull request Jun 7, 2022
_This version supports Xcode 14 beta 1_

* `PurchasesOrchestrator.handleDeferredTransaction`: check `NSError.domain` too (#1665) via NachoSoto (@NachoSoto)
* `PurchasesOrchestrator`: replaced manual `Lock` with `Atomic` (#1664) via NachoSoto (@NachoSoto)
* `CodableStrings.decoding_error`: added underlying error information (#1668) via NachoSoto (@NachoSoto)
* Fixed Xcode 14 compilation: avoid `@available` properties (#1661) via NachoSoto (@NachoSoto)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants