AFURLConnectionOperation'start'方法在准备好之前被调用,之后再也不会调用 [英] AFURLConnectionOperation 'start' method gets called before it is ready and never gets called again afterwards

查看:98
本文介绍了AFURLConnectionOperation'start'方法在准备好之前被调用,之后再也不会调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们在应用程序中使用AFNetworking( https://github.com/AFNetworking/AFNetworking ), NSOperationStack( https://github.com/nicklockwood/NSOperationStack )设置依赖项,以便最后一个操作获得优先级超过队列中的其余部分(堆栈行为)。调用AFURLConnectionOperation的开始方法时遇到一个问题,但是由于依赖关系,操作的 isReady方法返回NO。这使开始立即退出。在第一次尝试开始操作之后, start方法再也不会被调用,因此操作永远不会达到isFinished状态,永远不会从队列中删除,最终会阻塞队列。我对此事有任何想法将不胜感激。谢谢!

We use AFNetworking (https://github.com/AFNetworking/AFNetworking) in our app and NSOperationStack (https://github.com/nicklockwood/NSOperationStack) to set dependencies so that last operation gets priority over the rest in the queue (stack behavior). I am running into an issue when 'start' method of AFURLConnectionOperation gets called, but operation's 'isReady' method returns NO because of the dependencies. This makes 'start' exit immediately. After the very first attempt to start operation, 'start' method never gets called again, thus the operation never reaches isFinished state, never gets deleted from the queue and eventually operations like that jam the queue. I would appreciate any thought on this matter. Thank you!

更多信息:没有任何操作被取消,并且队列中没有任何依赖项圈。
我们在不更改AFNetworking代码的现有operationQueue上使用setLIFODependendenciesForOperation:[self.operationQueue setLIFODependendenciesForOperation:operation];

More info: none of the operations got cancelled and i don't see any dependency circles in the queue. We use setLIFODependendenciesForOperation on existing operationQueue not changing AFNetworking code: [self.operationQueue setLIFODependendenciesForOperation:operation];

更新:现在,更多地考虑它,是吗可能在某一时刻具有零依赖关系,并且当NSOperationQueue决定操作准备就绪时,具有isReady返回YES,但是到那时,调用start()时,依赖关系的数量变为1或更多。

Update: Now, thinking more about it, is it possible to have zero dependencies at one point and having isReady return YES when NSOperationQueue decides that operation is ready, but, by the time, start() gets invoked the number of dependencies changes to 1 or more.

推荐答案

这听起来像是您正在使用的'NS'OperationStack Github项目的问题。

This sounds like an issue with the 'NS'OperationStack Github project that you are using.

将依赖关系添加到 NSOperationQueue 后更改 NSOperation 在文档中特别建议不要这样做:

Changing NSOperation dependancies after they have been added to the NSOperationQueue is specifically advised against in the documentation:


重要在运行或添加操作之前,应始终配置依赖关系到操作队列。之后添加的依赖关系可能不会阻止给定的操作对象运行。 (来源:并发编程指南:配置互操作依赖性

Important You should always configure dependencies before running your operations or adding them to an operation queue. Dependencies added afterward may not prevent a given operation object from running. (From: Concurrency Programming Guide: Configuring Interoperation Dependencies)

I认为更好的方法是将自己的 LIFO 堆栈保持在操作队列之外,并使用一个操作的完成来触发下一个最重要的操作的排队。

I think a better approach would be to maintain your own LIFO stack outside the operation queue and use the finishing of one operation to trigger the queuing of the next most important operation.

或者,如果不需要严格要求,可以使用-[NSOperation setPriority:] 设置优先级较之较早的操作。

Or if you don't need to be strict perhaps you could use -[NSOperation setPriority:] to prioritise the later operations over the earlier ones.

这篇关于AFURLConnectionOperation'start'方法在准备好之前被调用,之后再也不会调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆