[ios, osx] Invalidate task immediately upon removal

This commit is contained in:
Minh Nguyễn
2016-03-09 08:36:10 -08:00
committed by Minh Nguyễn
parent e218728f3a
commit c335847451
2 changed files with 8 additions and 3 deletions

View File

@@ -70,8 +70,13 @@ typedef void (^MGLOfflineTaskListingCompletionHandler)(NS_ARRAY_OF(MGLOfflineTas
/**
Unregisters the given offline task and frees any resources that are no longer
required by any remaining tasks. After this task is removed, it is invalid; any
attempt to interact with it will result in an exception being thrown.
required by any remaining tasks.
As soon as this method is called on a task, the task becomes invalid; any
attempt to send it a message will result in an exception being thrown. If an
error occurs and the task cannot be removed, do not attempt to reuse the task
object. Instead, use the `-getTasksWithCompletionHandler:` method to obtain a
valid pointer to the task object.
@param task The offline task to remove.
@param completion The completion handler to call once the task has been

View File

@@ -104,6 +104,7 @@
}
- (void)removeTask:(MGLOfflineTask *)task withCompletionHandler:(MGLOfflineTaskRemovalCompletionHandler)completion {
[task invalidate];
self.mbglFileSource->deleteOfflineRegion(std::move(*task.mbglOfflineRegion), [&, task, completion](std::exception_ptr exception) {
NSError *error;
if (exception) {
@@ -113,7 +114,6 @@
}
if (completion) {
dispatch_async(dispatch_get_main_queue(), [&, task, completion, error](void) {
[task invalidate];
completion(error);
});
}