I am currently working under the assumption that -performSelector:withObject:afterDelay:
does not utilize threading, but schedules an event to fire at a later date on the current thread. Is this correct?
More, specifically:
- (void) methodCalledByButtonClick {
for (id obj in array) {
[self doSomethingWithObj:obj];
}
}
static BOOL isBad = NO;
- (void) doSomethingWithObj:(id)obj {
if (isBad) {
return;
}
if ([obj isBad]) {
isBad = YES;
[self performSelector:@selector(resetIsBad) withObject:nil afterDelay:0.1];
return;
}
//Do something with obj
}
- (void) resetIsBad {
isBad = NO;
}
Is it guaranteed that -resetIsBad
will not be called until after -methodCalledByButtonClick
returns, assuming we are running on the main thread, even if -methodCalledByButtonClick
takes an arbitrarily long time to complete?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…