Skip to content

Commit

Permalink
Add property 'wakeUpMainThread'.
Browse files Browse the repository at this point in the history
  • Loading branch information
vlfm committed Aug 1, 2013
1 parent a044651 commit f8944e0
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
2 changes: 2 additions & 0 deletions src/SerialImageDecompressor.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

@property (nonatomic, weak) id <SerialImageDecompressorDelegate> delegate;

@property (atomic) BOOL wakeUpMainThread; // YES

- (void)postImageForDecompression:(UIImage *)image context:(id)context;
- (void)cancelOperations;

Expand Down
20 changes: 17 additions & 3 deletions src/SerialImageDecompressor.m
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,12 @@ @implementation SerialImageDecompressor {

- (id)init {
self = [super init];

_queue = [[NSOperationQueue alloc] init];
_queue.maxConcurrentOperationCount = 1;

_wakeUpMainThread = YES;

return self;
}

Expand All @@ -16,10 +20,20 @@ - (void)postImageForDecompression:(UIImage *)image context:(id)context {

UIImage *decompressedImage = [SerialImageDecompressor decompressImage:image];

CFRunLoopPerformBlock(CFRunLoopGetMain(), kCFRunLoopDefaultMode, ^ {
[self.delegate decompressor:self didDecompressImage:decompressedImage context:context];
if (self.wakeUpMainThread) {

dispatch_async(dispatch_get_main_queue(), ^{
[self.delegate decompressor:self didDecompressImage:decompressedImage context:context];
});

});
} else {

CFRunLoopPerformBlock(CFRunLoopGetMain(), kCFRunLoopDefaultMode, ^ {
[self.delegate decompressor:self didDecompressImage:decompressedImage context:context];
});

}

}];
}

Expand Down

0 comments on commit f8944e0

Please sign in to comment.