CoreStore
CoreStore copied to clipboard
Using DispatchGroup leads to issue with invocation CoreStore success and failure closures.
I faced with the issue that I never get code called group.leave() line. Looks like when we use DispatchGroup() waiting for all async calls but it does not call CoreStore success and failure blocks then.
let group = DispatchGroup()
group.enter()
if let workoutsDictionaries = serverResponse["other"] as? [[String: Any]] {
CoreStore.perform(
asynchronous: { (transaction) -> [WorkoutEntity]? in
let workouts = self.offlineModeService.mergedWorkouts(from: workoutsDictionaries, transaction: transaction)
return workouts
},
success: { (transactionWorkouts) in
guard let unwrappedTransactionWorkouts = transactionWorkouts else {
return
}
let workouts = CoreStore.fetchExisting(unwrappedTransactionWorkouts)
group.leave()
//completion(.data(workouts))
},
failure: { (error) in
//completion(.error(StackedError.coreDataObjectSavingFailed(error: error)))
group.leave()
}
)
}
group.wait()
You are likely causing a deadlock as perform(asynchronous:)
should never be waited on. Try to use perform(synchronous:)
instead.