I have a function that has a problem in it. The following line seems to require a delay in order to accurately process whatever data it's processing, but it's not getting that time and and as a result I'm getting the wrong result. The following line:
self.failure = failure
Seems to need about 5-7 seconds to execute, but the problem is that the next line of code is executed before it can finish.
I need to setup self.failure = failure
in a way where the rest of the code in the function executes inside a completion block once that line has finished. I'm just not sure how to do it.
I've tried creating a typedef for a completion block, but I have no idea how and where to execute it.
- (void)start:(BMPlaybackStartupProcessCompleteBlock)completion
failure:(BMPlaybackStartupProcessFailureBlock)failure // what is the error code at the start and end of this method?
{
NSParameterAssert(completion);
NSParameterAssert(failure);
self.completion = completion;
self.failure = failure;
NSOperation *jailBreakOperation = [self jailBreakCheckOperation];
NSOperation *metadata = [self metadataOperation];
NSOperation *ads = [self adsOperation];
NSOperation *mediaPlayer = [self mediaPlayerOperation];
NSOperation *progress = [self progressTrackerOperation];
NSOperation *final = [self finalOperation];
[final addDependency:mediaPlayer];
[final addDependency:progress];
if (ads)
{
[final addDependency:ads];
[ads addDependency:metadata];
}
[mediaPlayer addDependency:metadata];
[progress addDependency:metadata];
[metadata addDependency:jailBreakOperation];
[self.queue addOperation:final];
if (ads)
{
[self.queue addOperation:ads];
}
[self.queue addOperation:mediaPlayer];
[self.queue addOperation:progress];
[self.queue addOperation:metadata];
[self.queue addOperation:jailBreakOperation];
// INPUTS:
// - content ID
// - metadata component
// - media player component
// - ads component
// - location manager if required
// - auto play?
// OUTPUTS:
// - Possibly an error if not successful
// - metadata
// - playback details
}
I want self.failure = failure
to finish BEFORE the NSOperationQueue stuff executes.
failure();
but I'm a bit confused of why you'd want to call the fail block before you did a thing. – Julian F. Weinert