Skip to content

Commit

Permalink
Expose SyncSession.reconnect() (#8399)
Browse files Browse the repository at this point in the history
  • Loading branch information
tgoyne authored Oct 17, 2023
1 parent ca45253 commit f485d2a
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
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

0 comments on commit f485d2a

Please sign in to comment.