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

Expose SyncSession.reconnect() #8399

Merged
merged 1 commit into from
Oct 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
x.y.z Release notes (yyyy-MM-dd)
=============================================================
### Enhancements
* None.
* Expose `SyncSession.reconnect()`, which requests an immediate reconnection if
the session is currently disconnected rather than waiting for the normal
reconnect delay.

### Fixed
* <How to hit and notice issue? what was the impact?> ([#????](https://github.com/realm/realm-swift/issues/????), since v?.?.?)
Expand Down
17 changes: 17 additions & 0 deletions Realm/RLMSyncSession.h
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,23 @@ RLM_SWIFT_SENDABLE RLM_FINAL // is internally thread-safe
*/
- (void)resume;

/**
Request an immediate reconnection to the server if the session is disconnected.

Realm automatically reconnects after disconnects with an exponential backoff,
which is reset when the reachability handler reports a network status change.
In some scenarios an application may wish to skip the reconnect delay, such as
when an application receives the DidBecomeActive notification, which can be
done by calling this method. Calling this method is never required.

This method is asynchronous and merely skips the current reconnect delay, so
the connection state will still normally be disconnected immediately after
calling it.

Has no effect if the session is currently connected.
*/
- (void)reconnect;

/**
Register a progress notification block.

Expand Down
6 changes: 6 additions & 0 deletions Realm/RLMSyncSession.mm
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,12 @@ - (void)unpause {
}
}

- (void)reconnect {
if (auto session = _session.lock()) {
session->handle_reconnect();
}
}

static util::UniqueFunction<void(Status)> wrapCompletion(dispatch_queue_t queue,
void (^callback)(NSError *)) {
queue = queue ?: dispatch_get_main_queue();
Expand Down