Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is -[NSOperationQueue currentQueue] reliable?

I know that GCD's dispatch_get_current_queue has been deprecated, and it is an anti-pattern to use it for callbacks anyway, but is -[NSOperationQueue currentQueue] reliable to use, or does it suffer from the same problems that GCD's dispatch_get_current_queue has? (I just want it so I can assert that I'm on the proper queue when my operation executes.)

like image 610
Heath Borders Avatar asked Feb 04 '26 03:02

Heath Borders


1 Answers

dispatch_get_current_queue was not deprecated because it's unreliable. It's deprecated because nearly all uses of it other than assertions are a bad idea, and because there can be more than one simultaneous current queue.

NSOperationQueue does not support target queues or synchronous execution, which are the two reasons the latter issue exists in dispatch, so it should be fine to use for assertions.

like image 182
Catfish_Man Avatar answered Feb 05 '26 20:02

Catfish_Man



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!