CoreStore icon indicating copy to clipboard operation
CoreStore copied to clipboard

App freezes till completion block gets called.

Open praveen-b27 opened this issue 7 years ago • 7 comments

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.

  1. print("CoreStore Called") is logged
  2. print("CoreStore Transit") is logged after few second (10Secs)
  3. 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.
  4. 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")
            })
        }

praveen-b27 avatar May 14 '18 09:05 praveen-b27

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:)?

JohnEstropia avatar May 14 '18 10:05 JohnEstropia

No, I used only perform(asynchronous) for all the corestore calls.

praveen-b27 avatar May 14 '18 10:05 praveen-b27

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.

JohnEstropia avatar Jun 10 '18 02:06 JohnEstropia

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.

praveen-b27 avatar Jun 11 '18 09:06 praveen-b27

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.

leacode avatar Sep 19 '19 06:09 leacode

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.

leacode avatar Sep 19 '19 07:09 leacode

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.

iosDeveloperAyaz avatar Feb 13 '22 20:02 iosDeveloperAyaz