Forked from artemstepanenko/NSOperationQueue+Completion.h
Last active
August 29, 2015 14:19
-
-
Save nsleader/e5c1bbd4ab92df7f1e65 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // | |
| // NSOperationQueue+Completion.h | |
| // QueueTest | |
| // | |
| // Created by Artem Stepanenko on 23.11.13. | |
| // Copyright (c) 2013 Artem Stepanenko. All rights reserved. | |
| // | |
| typedef void (^NSOperationQueueCompletion) (void); | |
| @interface NSOperationQueue (Completion) | |
| /** | |
| * Remarks: | |
| * | |
| * 1. Invokes completion handler just a single time when previously added operations are finished. | |
| * 2. Completion handler is called in a main thread. | |
| */ | |
| - (void)setCompletion:(NSOperationQueueCompletion)completion; | |
| @end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // | |
| // NSOperationQueue+Completion.m | |
| // QueueTest | |
| // | |
| // Created by Artem Stepanenko on 23.11.13. | |
| // Copyright (c) 2013 Artem Stepanenko. All rights reserved. | |
| // | |
| #import "NSOperationQueue+Completion.h" | |
| @implementation NSOperationQueue (Completion) | |
| - (void)setCompletion:(NSOperationQueueCompletion)completion | |
| { | |
| NSOperationQueueCompletion copiedCompletion = [completion copy]; | |
| dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ | |
| [self waitUntilAllOperationsAreFinished]; | |
| dispatch_async(dispatch_get_main_queue(), ^{ | |
| copiedCompletion(); | |
| }); | |
| }); | |
| } | |
| @end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment