Closed gogovan-anthonychan closed 3 years ago
@gogovan-anthonychan You need to observe the Realm collection for changes, as the test will continue without waiting for the write to finish. Once the change has been observed you can let your test continue. One way to implement this 'traffic light' system is to use a semaphore
Also see observing a collection a Realm: https://realm.io/docs/swift/latest/#collection-notifications
@leemaguire We have thought about this approach. Sometimes, we would like to make it synchronous. Save an object and then query it from other place. How can we ensure that the saving process finish other than realm notification?
To make it synchronous you will need to run everything off the same queue, otherwise the use of a semaphore is needed to ensure all other tasks have completed before continuing to the next.
@leemaguire if delete
and save
are running in the same queue, and the order is save -> delete
. Does it finish save
process before delete
every time?
Yes as long as you are using a serial queue.
@leemaguire I think you have solved my problem so I close this issue. Thank you.
Goals
We are going to move the writing process to the background thread and all other threads can get the updated detached result.
Expected Results
When querying that object, I still can get the object.
Steps for others to Reproduce
Run the unit test
Code Sample
Detaching helper
The failed unit test
model
Version of Realm and Tooling
Realm framework version: v5.4.3
Realm Object Server version: ---
Xcode version: Xcode 12.1
iOS/OSX version: 10.15.7
Dependency manager + version: carthage 0.36.0