5

With the arrival of combine framework, is there a need to use operation queues anymore. For example, apple uses operation queues almost all over the place in WWDC app. So if we use SwiftUI with combine(asynchronous programming), will there be a need to use Operation Queues?

Reckoner
  • 1,041
  • 2
  • 13
  • 29
  • What does the combine framework on its own has to do with operation queues? Do you expect that now since we have a combine framework there is no need for operation queues? Why do you think that? – J. Doe Jul 09 '19 at 07:52
  • 1
    @J.Doe I don't know. I am confused, and I need to implement it to see how it will work. But, it was just something that came in my mind and since I couldn't find any sources regarding this, I decided to post it here. – Reckoner Jul 09 '19 at 08:45

1 Answers1

12

Combine is just another asynchronous pattern, but doesn’t supplant operation queues (or dispatch queues). Just as GCD and operation queues happily coexist in our code bases, the same is true with Combine.

  • GCD is great at easy-to-write, yet still highly performant, code to dispatching tasks to various queues. So if you have something that might risk blocking the main thread, GCD makes it really easy to dispatch that to a background thread, and then dispatch some completion block back to the main thread. It also handles timers on background threads, data synchronization, highly-optimized parallelized code, etc.

  • Operation queues are great for higher-level tasks (especially those that are, themselves, asynchronous). You can take these pieces of work, wrap them up in discrete objects (for nice separation of responsibilities) and the operation queues manage execution, cancelation, and constrained concurrency, quite elegantly.

  • Combine shines at writing concise, declarative, composable, asynchronous event handling code. It excels at writing code that outlines how, for example, one’s UI should reflect some event (network task, notification, even UI updates).

This is obviously an oversimplification, but those are a few of the strengths of the various frameworks. And there is definitely overlap in these three frameworks, for sure, but each has its place.

Rob
  • 415,655
  • 72
  • 787
  • 1,044