App freezes till completion block gets called.
Below is the piece of code I'm using to store the products details, I will be getting huge data which has more than 7000 products.
- print("CoreStore Called") is logged
- print("CoreStore Transit") is logged after few second (10Secs)
- App freezes after transit is logged till it comes to completion block. Still its a asynchronous process but not sure why the UI gets blocked for few seconds.
- Once the "CoreStore Completed" is logged its working fine.
Kindly let me know why the UI is getting blocked when it get stored.
DispatchQueue.global().async {
print("CoreStore Called")
CoreStore.perform(asynchronous: { (transaction) in
if let data = response["productCategories"].arrayObject as? [[String: Any]] {
let _ = try transaction.importUniqueObjects(
Into<Categories>(),
sourceArray: data
)
}
print("CoreStore Transit")
}, completion: { (result) in
print("CoreStore Completed")
})
}
First, you don't need to dispatch the peform(asynchronous:) call from DispatchQueue.global(). CoreStore will manage this for you.
As for the blocking UI thread issue, do you have anywhere in your code where you are using perform(synchronous:)?
No, I used only perform(asynchronous) for all the corestore calls.
Have you resolved this issue? Note that ListMonitors and other observers will be notified right after commit, which would be just before the completion closure is called. It's possible you have an observer somewhere that is taking a long time and is blocking the UI thread.
I'm not using any List Monitors or observers to notify UI, waiting til the completion calls and trying to update my UI. But my app freezes few seconds until completion block gets called. This is happening all the time.
Get the same issue here. Just called CoreStore.perform(asynchronous: ... ) to update some value. No other observer exist. The app freeze and never enter completion block.
Problem solved. First, do not call several update at the same time. Second, do not use try? or try!, I read it from the readme file.
I am facing same issue, App Freeze until and unless, completion not called. I called right before loader but it is also called after completion , even I can interact with app.