|
@@ -44,12 +44,8 @@ class ProductsInfoController: NSObject {
|
|
|
}
|
|
|
|
|
|
let inAppProductRequestBuilder: InAppProductRequestBuilder
|
|
|
-
|
|
|
- private var spinLock: OSSpinLock
|
|
|
-
|
|
|
init(inAppProductRequestBuilder: InAppProductRequestBuilder = InAppProductQueryRequestBuilder()) {
|
|
|
self.inAppProductRequestBuilder = inAppProductRequestBuilder
|
|
|
- self.spinLock = OSSpinLock()
|
|
|
}
|
|
|
|
|
|
// As we can have multiple inflight requests, we store them in a dictionary by product ids
|
|
@@ -57,18 +53,10 @@ class ProductsInfoController: NSObject {
|
|
|
|
|
|
@discardableResult
|
|
|
func retrieveProductsInfo(_ productIds: Set<String>, completion: @escaping (RetrieveResults) -> Void) -> InAppProductRequest {
|
|
|
- OSSpinLockLock(&self.spinLock)
|
|
|
- defer {
|
|
|
- OSSpinLockUnlock(&self.spinLock)
|
|
|
- }
|
|
|
|
|
|
if inflightRequests[productIds] == nil {
|
|
|
let request = inAppProductRequestBuilder.request(productIds: productIds) { results in
|
|
|
- OSSpinLockLock(&self.spinLock)
|
|
|
- defer {
|
|
|
- OSSpinLockUnlock(&self.spinLock)
|
|
|
- }
|
|
|
-
|
|
|
+
|
|
|
if let query = self.inflightRequests[productIds] {
|
|
|
for completion in query.completionHandlers {
|
|
|
completion(results)
|