Async completion never get called #439

Closed
opened 2025-12-29 18:26:59 +01:00 by adam · 0 comments
Owner

Originally created by @imrobbyrc on GitHub (Jan 20, 2025).

Omni.dataStack.perform(
  asynchronous: { (transaction) -> [Omni.Store] in
      let tags = try! transaction.importUniqueObjects(Into<Omni.StoreTag>(),
                                                      sourceArray: json["tags"].arrayValue)

      let tagMapping = tags.reduce(into: [Int: Omni.StoreTag]()) { (result, object) in
          result[object.id] = object
      }

      let stores = try transaction.importUniqueObjects(
          Into<Omni.Store>(), sourceArray: json["stores"].arrayValue, preProcess: { mapping in
              var storeMapping = [Int: JSON]()
              for (key, storeJson) in mapping {
                  guard var dict = storeJson.dictionaryObject else { continue }

                  var tagObjects = Set<Omni.StoreTag>()
                  for tagId in storeJson["tag_ids"].arrayValue {
                      if let tag = tagMapping[tagId.intValue] {
                          tagObjects.insert(tag)
                      }
                  }
                  dict["merchant_id"] = merchantId
                  dict["tag_objects"] = tagObjects
                  storeMapping[key] = JSON(dict)
              }
              return storeMapping
          }
      )

     for store in stores {
          guard let transactionStore = transaction.edit(store) else { continue }
          if let storeJson = storeJsonMapping[transactionStore.id],
             let operatingHourJson = storeJson["operating_hours"].arrayValue
              .first(where: { $0["day"].intValue == Date().omniWeekday }) {
              guard var dict = operatingHourJson.dictionaryObject else { continue }
              dict["store_object"] = store
              try transaction.importUniqueObject(
                  Into<Omni.OperatingHour>(),
                  source: JSON(dict))
          }
      }

      return stores
  },
  completion: { result in }

hi @JohnEstropia, do you know why the completion handler never get called for that code block? if i disable the block for store in stores, it working normally, i try to in synchronous it working as expected

Originally created by @imrobbyrc on GitHub (Jan 20, 2025). ```swift Omni.dataStack.perform( asynchronous: { (transaction) -> [Omni.Store] in let tags = try! transaction.importUniqueObjects(Into<Omni.StoreTag>(), sourceArray: json["tags"].arrayValue) let tagMapping = tags.reduce(into: [Int: Omni.StoreTag]()) { (result, object) in result[object.id] = object } let stores = try transaction.importUniqueObjects( Into<Omni.Store>(), sourceArray: json["stores"].arrayValue, preProcess: { mapping in var storeMapping = [Int: JSON]() for (key, storeJson) in mapping { guard var dict = storeJson.dictionaryObject else { continue } var tagObjects = Set<Omni.StoreTag>() for tagId in storeJson["tag_ids"].arrayValue { if let tag = tagMapping[tagId.intValue] { tagObjects.insert(tag) } } dict["merchant_id"] = merchantId dict["tag_objects"] = tagObjects storeMapping[key] = JSON(dict) } return storeMapping } ) for store in stores { guard let transactionStore = transaction.edit(store) else { continue } if let storeJson = storeJsonMapping[transactionStore.id], let operatingHourJson = storeJson["operating_hours"].arrayValue .first(where: { $0["day"].intValue == Date().omniWeekday }) { guard var dict = operatingHourJson.dictionaryObject else { continue } dict["store_object"] = store try transaction.importUniqueObject( Into<Omni.OperatingHour>(), source: JSON(dict)) } } return stores }, completion: { result in } ``` hi @JohnEstropia, do you know why the completion handler never get called for that code block? if i disable the block for store in stores, it working normally, i try to in synchronous it working as expected
adam closed this issue 2025-12-29 18:26:59 +01:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/CoreStore-JohnEstropia#439