When working with some code, I come across cycle loops for which I am new to inside NSOperation s.
NSOperation are busy loading data - and while they are busy, there is code waiting for the download to complete, in the form of NSRunLoop and a sleeping stream.
This code, in particular, interests me:
while (aCertainConditionIsTrue && [self isCancelled]==NO) { if(![[NSRunLoop currentRunLoop] runMode: NSDefaultRunLoopMode beforeDate:[NSDate dateWithTimeIntervalSinceNow:1.0]]){ [NSThread sleepForTimeInterval:1.0]; } }
I read about startup loops, and runMode:beforeDate: will wait for an input source or timeout. Although I am not 100% what is considered input juice.
The first time this is done, it always returns NO and calls sleepForTimeInterval: This is bad?
In a particular utility class, it strikes sleepForTimeInterval: many times - once for each thread, which significantly degrades performance.
Any better solutions or tips?
source share