【发布时间】:2019-11-12 15:40:25
【问题描述】:
我有一个有问题的函数。以下行似乎需要延迟才能准确处理它正在处理的任何数据,但它没有得到那个时间,因此我得到了错误的结果。以下行:
self.failure = failure
执行似乎需要5-7秒左右,但问题是下一行代码还没完成就执行完毕。
我需要设置self.failure = failure,使函数中的其余代码在该行完成后在完成块内执行。我只是不知道该怎么做。
我尝试为完成块创建 typedef,但我不知道如何以及在何处执行它。
- (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
}
我希望self.failure = failure 在 NSOperationQueue 内容执行之前完成。
【问题讨论】:
-
您需要实际调用该块。现在你将它分配给一个属性,我不相信这需要更多的时间。调用函数看起来像
failure();,但我有点困惑为什么你要在做某事之前调用失败块。 -
我猜第一个操作需要很长时间。你会想在失败的情况下调用块,或者在一切完成后调用成功块。但请记住,您的操作不会异步运行,但很难说其余代码的作用。
标签: objective-c objective-c-blocks