-
Notifications
You must be signed in to change notification settings - Fork 2.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for cancelling async opens #6193
Conversation
Make Realm.asyncOpen() return an AsyncOpenTask which can be used to get download progress notifications or cancel the async open.
Realm is downloaded from the server before the completion callback is invoked. | ||
This task object can be used to observe the state of the download or to cancel | ||
it. This should be used instead of trying to observe the download via the sync | ||
session as the sync session itself is created asynchronously, and may not exist |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this Cocoa specific? The sync session is created here: https://github.com/realm/realm-object-store/blob/master/src/impl/realm_coordinator.cpp#L311 Which is called synchronously as part of calling RealmCoordinator::get_synchronized_realm()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The very first thing that Cocoa's asyncOpen does is dispatch to a background queue, and get_synchronized_realm() is called from there.
invoked. This task object can be used to observe the state of the download | ||
or to cancel it. This should be used instead of trying to observe the | ||
download via the sync session as the sync session itself is created | ||
asynchronously, and may not exist yet when Realm.asyncOpen() returns. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same
@@ -276,12 +289,15 @@ + (void)asyncOpenWithConfiguration:(RLMRealmConfiguration *)configuration | |||
} | |||
}; | |||
|
|||
dispatch_async(queue, ^{ | |||
RLMAsyncOpenTask *ret = [RLMAsyncOpenTask new]; | |||
dispatch_async(s_async_open_queue, ^{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why move this to its own queue?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The only change here is to let the tests override the queue used, so that they can make it use a serial queue rather than the default of a concurrent queue to ensure that things happen in the desired order.
If the question is just "why is there a background queue involved at all?" then it's because there is a bit of i/o and cpu done on the source thread even as part of get_synchronized_realm().
Make Realm.asyncOpen() return an AsyncOpenTask which can be used to get download progress notifications or cancel the async open.