OperationQueueScheduler

To work with the operation queue API instead of GCD, first we need to create an OperationQueue instance and then create an OperationQueueScheduler with that operation queue, as follows:

let opQueue = OperationQueue()let opQueueScheduler = OperationQueueScheduler(operationQueue: opQueue)

Finally, we can use the opQueueScheduler instead of the serial queue scheduler with the ObserveOn operator, as demonstrated:

imageData    .observeOn(opQueueScheduler)    .map { UIImage(data: $0) }    .observeOn(MainScheduler.instance)    .subscribe(onNext: {        imageView.image = $0    })    .disposed(by: disposeBag)

The overall code for this demonstration can be summarized as follows:

import PlaygroundSupportPlaygroundPage.current.needsIndefiniteExecution ...

Get Reactive Programming with Swift 4 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.