Skip to content

Commit

Permalink
Fix async bug
Browse files Browse the repository at this point in the history
  • Loading branch information
danielsaidi committed May 3, 2024
1 parent 727d47c commit f7f6eb8
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
6 changes: 6 additions & 0 deletions RELEASE_NOTES.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
# Release notes


## 0.3.1

This version fixes an async error that could cause purchases to update the context on a background thread.



## 0.3

StoreKitPlus now uses Swift 5.9, which requires Xcode 15.
Expand Down
10 changes: 7 additions & 3 deletions Sources/StoreKitPlus/Services/StandardStorePurchaseService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@ open class StandardStorePurchaseService: StorePurchaseService {
private let context: StoreContext
private var transactionTask: Task<Void, Error>?

open func purchase(_ product: Product) async throws -> Product.PurchaseResult {
open func purchase(
_ product: Product
) async throws -> Product.PurchaseResult {
#if os(visionOS)
throw StoreServiceError.unsupportedPlatform("This purchase operation is not supported in visionOS: Use @Environment(\\.purchase) instead.")
#else
Expand Down Expand Up @@ -114,10 +116,12 @@ private extension StandardStorePurchaseService {
var transactions = context.purchaseTransactions
.filter { $0.productID != transaction.productID }
transactions.append(transaction)
context.purchaseTransactions = transactions
updateContext(with: transactions)
}

func updateContext(with transactions: [Transaction]) {
context.purchaseTransactions = transactions
DispatchQueue.main.async {
self.context.purchaseTransactions = transactions
}
}
}

0 comments on commit f7f6eb8

Please sign in to comment.