Skip to content
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

Merged
merged 1 commit into from
Jul 10, 2019
Merged

Add support for cancelling async opens #6193

merged 1 commit into from
Jul 10, 2019

Conversation

tgoyne
Copy link
Member

@tgoyne tgoyne commented Jul 1, 2019

Make Realm.asyncOpen() return an AsyncOpenTask which can be used to get download progress notifications or cancel the async open.

Make Realm.asyncOpen() return an AsyncOpenTask which can be used to get
download progress notifications or cancel the async open.
@tgoyne tgoyne self-assigned this Jul 1, 2019
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
Copy link
Contributor

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()

Copy link
Member Author

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.
Copy link
Contributor

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, ^{
Copy link
Contributor

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?

Copy link
Member Author

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().

@tgoyne tgoyne merged commit 939d89f into master Jul 10, 2019
@tgoyne tgoyne deleted the tg/async-open-task branch July 10, 2019 18:22
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 15, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants