O'Reilly logo

Reactive Programming with Swift 4 by Navdeep Singh

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Specifying a scheduler

To specify a scheduler on which a subscription is created, handler-executed, and disposed of, we use the subscribeOn operator. This is not normally used; instead, we just use ObserverOn, which specifies the scheduler events: next, error, and completed. The important thing to remember is that subscribeOn will direct which scheduler a subscription operates, whereas ObserveOn will only direct which scheduler to use after or below where ObserveOn is used in a chain. Let's look at this in a marble diagram first and then jump into a code example in the coming section.

We are starting on in the main thread, which is represented by the timeline here:

We will call ObserverOn and specify scheduler1, as shown:

Imagine that we ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required