6

I want to add operation into executing request. I read about ASINetworkQueue, but it adds all operation and run it all. but i want to add operation into running queue.

Is this possible? using ASIHTTPRequest or AFNetworking i don't mind, as long as i get what i intend to do.

EDIT

It shows below error while i try to add another request.

[ASINetworkQueue addOperation:]: operation is executing and cannot be enqueued'

HelmiB
  • 12,303
  • 5
  • 41
  • 68
  • What exactly is the issue here? Your request is currently executing or Queue is is already executing some operations? You cannot add a operation to a queue if the operation is already executing in another queue. Is that what you are looking for? – iDev Dec 04 '12 at 06:55
  • Yes, My queue still executing, but I want to add another queue in the operation. is this possible? how bout in `AFNetworking`? – HelmiB Dec 04 '12 at 07:10
  • I am getting confused. Your operation is executing and you want to add to another queue? A queue can be executing some other operation and you can add any operation at that time. – iDev Dec 04 '12 at 07:13
  • Yes, My Operations (in Queue) is executing and i want to add another operation into queue. – HelmiB Dec 04 '12 at 07:15
  • 1
    So are you sure that the current operation which you are trying to add is not executing currently? If it is not executing you should be able to add to a Queue. The above error message is displayed normally when an operation is executing and then you are trying to add to some queue. – iDev Dec 04 '12 at 07:17
  • 1
    No, it is executing. that's why the error above shown. I'm looking other alternative or workaround – HelmiB Dec 04 '12 at 07:30
  • So is it not possible to execute it after adding to queue? Because NSOperationQueue will not allow to add an operation which is executing. I am afraid there is anything you can do on that. – iDev Dec 04 '12 at 07:36

2 Answers2

11

From the apple documentation for addOperation: it is clear that you cannot add an operation which is executing into a NSOperationQueue.

This is what mentioned there,

An operation object can be in at most one operation queue at a time and this method throws an NSInvalidArgumentException exception if the operation is already in another queue. Similarly, this method throws an NSInvalidArgumentException exception if the operation is currently executing or has already finished executing.

That is the default behavior of NSOperationQueue. You need to make sure that the NSOperation is not executing before adding to queue. There are various properties such as isExecuting, isFinished etc.. to check this.

iDev
  • 23,310
  • 7
  • 60
  • 85
  • 9
    Even if your operation is not `isExecuting` and `isFinished`, the error `operation is executing and cannot be enqueued` will be thrown if you will try to enqueue same operation in same queue twice. You must reinit the operation before enqueue it again in same queue. – kas-kad Dec 12 '14 at 12:42
0

You just call addOperation on the request queue. In asi for its ASiNetworkQueue it shouldn't mattter if it is running or not.

Daij-Djan
  • 49,552
  • 17
  • 113
  • 135
  • hmm... i read resource says different. can't add operation that is running. you sure? i haven't try though, will give it a try tomorrow. thanks. – HelmiB Nov 14 '12 at 08:51
  • well, I havent tried it but from the code and the header docs it doesnt look like it wont work – Daij-Djan Nov 14 '12 at 09:17
  • of course an NSOperationQueue (ASI or AFN) is always append only though you can work with dependencies – Daij-Djan Nov 14 '12 at 09:18
  • apparently it cannot. it shows : `[ASINetworkQueue addOperation:]: operation is executing and cannot be enqueued'` – HelmiB Nov 28 '12 at 01:17