Originally created by @matrosovDev on GitHub (May 4, 2019).
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()
Originally created by @matrosovDev on GitHub (May 4, 2019).
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()
```
adam
added the question label 2025-12-29 15:28:00 +01:00
You are likely causing a deadlock as perform(asynchronous:) should never be waited on. Try to use perform(synchronous:) instead.
@JohnEstropia commented on GitHub (May 6, 2019):
You are likely causing a deadlock as `perform(asynchronous:)` should never be waited on. Try to use `perform(synchronous:)` instead.
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
Originally created by @matrosovDev on GitHub (May 4, 2019).
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.
@JohnEstropia commented on GitHub (May 6, 2019):
You are likely causing a deadlock as
perform(asynchronous:)should never be waited on. Try to useperform(synchronous:)instead.