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

connectionDidFinishLoading #872

Closed
TaoXiaoSeng opened this issue Aug 19, 2014 · 2 comments
Closed

connectionDidFinishLoading #872

TaoXiaoSeng opened this issue Aug 19, 2014 · 2 comments
Milestone

Comments

@TaoXiaoSeng
Copy link

i see the code like this
1:

  • (void)connectionDidFinishLoading:(NSURLConnection *)aConnection {
    SDWebImageDownloaderCompletedBlock completionBlock = self.completedBlock;
    @synchronized(self) {
    CFRunLoopStop(CFRunLoopGetCurrent());
    self.thread = nil;
    self.connection = nil;
    [[NSNotificationCenter defaultCenter] postNotificationName:SDWebImageDownloadStopNotification object:nil];
    }
    ......

2:

  • (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error {
    CFRunLoopStop(CFRunLoopGetCurrent());
    [[NSNotificationCenter defaultCenter] postNotificationName:SDWebImageDownloadStopNotification object:nil];

    if (self.completedBlock) {
    self.completedBlock(nil, nil, error, YES);
    }
    .....

this two functions are the delegate callback for NSURLConnection normally.
but in sdwebimage, it only do some special operations in connectionDidFinishLoading.

@synchronized(self) {
CFRunLoopStop(CFRunLoopGetCurrent());
self.thread = nil;
self.connection = nil;
[[NSNotificationCenter defaultCenter] postNotificationName:SDWebImageDownloadStopNotification object:nil];
}

i think this code is used to race conditions with cancel operation. is it true?
If so, why this code only write in connectionDidFinishLoading, what about the function - (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error ?

i hope you could tell me the reason. thanks very much!

@bpoplauschi
Copy link
Member

@TaoXiaoSeng thanks for noticing this, indeed both functions have to have the same behavior

@bpoplauschi bpoplauschi added this to the 4.0.0 milestone Nov 2, 2014
@TaoXiaoSeng
Copy link
Author

OK, just like i thought before

@bpoplauschi bpoplauschi modified the milestones: 3.7.2, 4.0.0 Mar 19, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants