Questions tagged [nsoperationqueue]

On Mac OS X, the NSOperationQueue class regulates the execution of a set of NSOperation objects.

The NSOperationQueue class regulates the execution of a set of NSOperation () objects. After being added to a queue, an operation remains in that queue until it is explicitly canceled or finishes executing its task. Operations within the queue (but not yet executing) are themselves organized according to priority levels and inter-operation object dependencies and are executed accordingly. An application may create multiple operation queues and submit operations to any of them.

References:

1047 questions
10
votes
1 answer

Solve reader-writer issues with NSOperationQueue?

I know it's possible to solve reader-writer issues in GCD using barriers. Since I (generally) try to use NSOperationQueue instead of GCD when performance isn't a key issue, I'd like an NSOperation-compatible solution to this issue. I've tried to…
10
votes
6 answers

Get underlying dispatch_queue_t from NSOperationQueue

I seem to have some confusion between dispatch_queue_t and NSOperationQueue queues. By default, AFNetworking's AFImageRequestOperation will execute the success callback block on the application's main thread. To change this, AFHTTPRequestOperation…
Jonas Sourlier
  • 13,684
  • 16
  • 77
  • 148
10
votes
3 answers

is there a way to add blocks to NSOperationQueue like this

I am trying to understand NSOperationQueue's and am trying to create the most simple example possible. I have the following: NSOperationQueue *myOQ=[[NSOperationQueue alloc] init]; [myOQ addOperationWithBlock:^(void){ NSLog(@"here is something…
timpone
  • 19,235
  • 36
  • 121
  • 211
10
votes
1 answer

AFNetworking - Why does it spawn a network request thread?

I'm trying to understand Operations and Threads better, and looked to AFNetworking's AFURLConnectionOperation subclass for example, real-world, source code. My current understanding is when instances of NSOperation are added to an operation queue,…
edelaney05
  • 6,822
  • 6
  • 41
  • 65
9
votes
2 answers

cancelAllOperations doesn't work for [NSOperationQueue mainQueue]

cancelAllOperations() doesn't work on the mainQueue (the cancel() method is not called on the NSOperation object). Am I missing something? I have to iterate through all operations and call the cancel() method to get it work.
Alexander
  • 1,495
  • 2
  • 19
  • 24
9
votes
2 answers

GCD, NSOperationQueue, or create a thread manually?

When you use threads, do you have any preferences? In general rule, to use any of these techniques : create a new thread manually and use the run loop use NSOperationQueue or use Grand Central Dispatch and the C version with dispatch_queue? Does…
Paul
  • 6,108
  • 14
  • 72
  • 128
9
votes
1 answer

Swift 5.5 Concurrency: how to serialize async Tasks to replace an OperationQueue with maxConcurrentOperationCount = 1?

I’m currently migrating my app to use the concurrency model in Swift. I want to serialize Tasks to make sure they are executed one after the other (no paralellism). In my use case, I want to listen to notifications posted by the NotificationCenter…
9
votes
2 answers

iOS - How to check if an NSOperation is in an NSOperationQueue?

From the docs: 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…
Bryan Chen
  • 45,816
  • 18
  • 112
  • 143
9
votes
3 answers

NsoperationQueue Cancel all operations is not cancelled until it finishes the operation

In my view i have image view, the data for image view comes form Url, the images are around 1-3 MB . If the user Swipes then i want to load the next image, Every thing works fine if swiped slowly, But when i swiped Fastly I want to Cancel the…
siva krishna
  • 1,149
  • 2
  • 15
  • 23
9
votes
3 answers

How can an NSOperationQueue wait for two async operations?

How can I make an NSOperationQueue (or anything else) wait for two async network calls with callbacks? The flow needs to look like this Block Begins { Network call with call back/block begins { first network call is done } } Second…
mergesort
  • 5,087
  • 13
  • 38
  • 63
9
votes
3 answers

Generic NSOperation subclass loses NSOperation functionality

Today I've met one weird issue when I was trying to 'generalize' my 'CoreData importing operations'. It appeared that if I create a generic subclass of NSOperation the main() func won't be called. Simple example: class MyOperation:…
Nevs12
  • 599
  • 6
  • 13
9
votes
1 answer

NSOperation is not happening in background thread

I created an NSOperation subclass to handle some zip archive operations. No matter what, if I override -start or -main this block of code always happens: if ([NSThread isMainThread]) { NSLog(@"I am in the main thread"); return; } Any idea…
Daddy
  • 9,045
  • 7
  • 69
  • 98
9
votes
4 answers

Log which queue/thread a method is running on

Is there a way to log the thread or queue that a method is running on / called from? Something like: - (void)foo { NSLog(@"Running on %@ queue, %@ thread", queue, thread); }
8
votes
1 answer

Can't cancel executing operations in OperationQueue swift

Im doing some lengthy calculations to create chart data on a background thread i was originally use GCD, but every time a user filters the chart data by hitting a button, the chart data needs to be recalculated, if the user clicks the chart data…
8
votes
0 answers

App crashed in Dispatch queue: NSOperationQueue

I sometimes get the following crash in my app: Crashed Thread: 4 Dispatch queue: NSOperationQueue 0x7fc2d96277c0 :: NSOperation 0x7fc2d9704440 (QOS: UTILITY) Exception Type: EXC_BAD_ACCESS (SIGSEGV) Exception Codes: …
Mugen
  • 8,301
  • 10
  • 62
  • 140