App freezes till completion block gets called. #212

Open
opened 2025-12-29 15:26:47 +01:00 by adam · 7 comments
Owner

Originally created by @praveen-b27 on GitHub (May 14, 2018).

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")
            })
        }
Originally created by @praveen-b27 on GitHub (May 14, 2018). 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") }) } ```
Author
Owner

@JohnEstropia commented on GitHub (May 14, 2018):

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 commented on GitHub (May 14, 2018): 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:)`?
Author
Owner

@praveen-b27 commented on GitHub (May 14, 2018):

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

@praveen-b27 commented on GitHub (May 14, 2018): No, I used only perform(asynchronous) for all the corestore calls.
Author
Owner

@JohnEstropia commented on GitHub (Jun 10, 2018):

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 commented on GitHub (Jun 10, 2018): 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.
Author
Owner

@praveen-b27 commented on GitHub (Jun 11, 2018):

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 commented on GitHub (Jun 11, 2018): 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.
Author
Owner

@leacode commented on GitHub (Sep 19, 2019):

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 commented on GitHub (Sep 19, 2019): 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.
Author
Owner

@leacode commented on GitHub (Sep 19, 2019):

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 commented on GitHub (Sep 19, 2019): 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.
Author
Owner

@iosDeveloperAyaz commented on GitHub (Feb 13, 2022):

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 commented on GitHub (Feb 13, 2022): 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.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/CoreStore#212