Skip to content

Instantly share code, notes, and snippets.

@Mozilla9
Last active April 17, 2019 16:52
Show Gist options
  • Save Mozilla9/16b0b5013256ff89e52b to your computer and use it in GitHub Desktop.
Save Mozilla9/16b0b5013256ff89e52b to your computer and use it in GitHub Desktop.
- (void)saveWebDataInternal:(TaxiSpecialPlacesHierarchyResponseModel *)data completion:(void(^)(NSArray *))completion
{
        NSBlockOperation *op = [[NSBlockOperation alloc] init];

        op.completionBlock = ^{
            dispatch_async(dispatch_get_main_queue(), ^{
                [self loadCachedDataInternal:completion];
            });
        };

        [op addExecutionBlock:^{
            dispatch_semaphore_t mutex = dispatch_semaphore_create(0);

            [self.relatedAddressesDAO asyncImportRelatedAddressHierarchy:data completion:^{
                dispatch_semaphore_signal(mutex);
            }];

            dispatch_semaphore_wait(mutex, DISPATCH_TIME_FOREVER);
        }];

        // start operations
        dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
            [op start];
        });
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment