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

Clear iOS platform instances synchronously #249

Merged
merged 9 commits into from Nov 29, 2021
9 changes: 1 addition & 8 deletions ios/Classes/AblyFlutter.h
Expand Up @@ -25,14 +25,7 @@ NS_ASSUME_NONNULL_BEGIN

-(ARTPaginatedResult *) getPaginatedResult:(NSNumber *const) handle;

/**
This method must be called from the main dispatch queue. It may only be called
once.

@param completionHandler Will be called on the main dispatch queue when all
platform objects have been closed down cleanly.
*/
ben-xD marked this conversation as resolved.
Show resolved Hide resolved
-(void)disposeWithCompletionHandler:(dispatch_block_t)completionHandler;
-(void)dispose;

@end

Expand Down
15 changes: 0 additions & 15 deletions ios/Classes/AblyFlutter.m
Expand Up @@ -126,21 +126,6 @@ -(ARTPaginatedResult *) getPaginatedResult:(NSNumber *const) handle {
return [_paginatedResults objectForKey:handle];
}

-(void)disposeWithCompletionHandler:(const dispatch_block_t)completionHandler {
if (!completionHandler) {
[NSException raise:NSInvalidArgumentException format:@"completionHandler cannot be nil."];
}

dispatch_assert_queue(dispatch_get_main_queue());

// This is contrived for now but the point is that we can introduce a clean,
// asynchronous close via a background queue here if required.
dispatch_async(dispatch_get_main_queue(), ^{
[self dispose];
completionHandler();
});
}

-(void)dispose {
for (ARTRealtime *const r in _realtimeInstances.allValues) {
[r close];
Expand Down
16 changes: 6 additions & 10 deletions ios/Classes/AblyFlutterPlugin.m
Expand Up @@ -22,7 +22,7 @@
static FlutterHandle declarations.
*/
@interface AblyFlutterPlugin ()
-(void)registerWithCompletionHandler:(FlutterResult)completionHandler;
-(void)reset:(FlutterResult)completionHandler;
@end

NS_ASSUME_NONNULL_END
Expand All @@ -36,7 +36,7 @@ -(void)registerWithCompletionHandler:(FlutterResult)completionHandler;
};

static const FlutterHandler _resetAblyClients = ^void(AblyFlutterPlugin *const plugin, FlutterMethodCall *const call, const FlutterResult result) {
[plugin registerWithCompletionHandler:result];
[plugin reset:result];
ben-xD marked this conversation as resolved.
Show resolved Hide resolved
};

static const FlutterHandler _createRestWithOptions = ^void(AblyFlutterPlugin *const plugin, FlutterMethodCall *const call, const FlutterResult result) {
Expand Down Expand Up @@ -652,14 +652,10 @@ -(void)handleMethodCall:(FlutterMethodCall*)call result:(FlutterResult)result {
}
}

-(void)registerWithCompletionHandler:(const FlutterResult)completionHandler {
if (!completionHandler) {
[NSException raise:NSInvalidArgumentException format:@"completionHandler cannot be nil."];
}
[_ably disposeWithCompletionHandler:^{
[self->_streamsChannel reset];
completionHandler(nil);
}];
-(void)reset:(const FlutterResult)result {
[_ably dispose];
[self->_streamsChannel reset];
result(nil);
}

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
Expand Down