Idea: Asynchronous fetching #73

Open
opened 2025-12-29 15:23:39 +01:00 by adam · 3 comments
Owner

Originally created by @JohnEstropia on GitHub (Aug 26, 2016).

Objective: allow a way to fetch objects in a way that can wait for completion of

  1. Store migrations (need to explicitly provide configuration in Into<Entity>("...") clause)
  2. Heavy queries
Originally created by @JohnEstropia on GitHub (Aug 26, 2016). Objective: allow a way to fetch objects in a way that can wait for completion of 1. Store migrations (need to explicitly provide configuration in `Into<Entity>("...")` clause) 2. Heavy queries
adam added the enhancement label 2025-12-29 15:23:39 +01:00
Author
Owner

@flyingcane commented on GitHub (Dec 27, 2017):

@JohnEstropia Hi JohnEstropia, it's a great open source for core data. Does CoreStore only support fetch records on the main thread? If a large number of records, does it block the main thread?

@flyingcane commented on GitHub (Dec 27, 2017): @JohnEstropia Hi JohnEstropia, it's a great open source for core data. Does CoreStore only support fetch records on the main thread? If a large number of records, does it block the main thread?
Author
Owner

@JohnEstropia commented on GitHub (Dec 27, 2017):

@evanxie-cn If you have very large fetches (e.g. image binary data, few thousand objects) you can always fetch from a background transaction and pass the info you need to the main thread. Here's an example:

dataStack.perform(
    asynchronous: { (transaction) -> [UIImage] in
        let people = transaction.fetchAll(From<Person>().where(/* ... */))
        return people.map { UIImage(data: $0.imageData)! }
    },
    completion: { (photos) in  /* ... */
        // use photos
    }
)

Depending on your confidence on your app architecture, you can also use unsafe transactions (dataStack.beginUnsafe()) in conjunction with your own DispatchQueues.

@JohnEstropia commented on GitHub (Dec 27, 2017): @evanxie-cn If you have very large fetches (e.g. image binary data, few thousand objects) you can always fetch from a background transaction and pass the info you need to the main thread. Here's an example: ```swift dataStack.perform( asynchronous: { (transaction) -> [UIImage] in let people = transaction.fetchAll(From<Person>().where(/* ... */)) return people.map { UIImage(data: $0.imageData)! } }, completion: { (photos) in /* ... */ // use photos } ) ``` Depending on your confidence on your app architecture, you can also use unsafe transactions (`dataStack.beginUnsafe()`) in conjunction with your own `DispatchQueue`s.
Author
Owner

@flyingcane commented on GitHub (Dec 28, 2017):

@JohnEstropia Thank you very much. I got it.

@flyingcane commented on GitHub (Dec 28, 2017): @JohnEstropia Thank you very much. I got it.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/CoreStore#73