Generic Instance Method


Specifies the scheduler on which to perform subscribe, cancel, and request operations.


func subscribe<S>(on scheduler: S, options: S.SchedulerOptions? = nil) -> Publishers.SubscribeOn<Publishers.Share<Upstream>, S> where S : Scheduler



The scheduler on which to receive upstream messages.


Options that customize the delivery of elements.

Return Value

A publisher which performs upstream operations on the specified scheduler.


In contrast with receive(on:options:), which affects downstream messages, subscribe(on:) changes the execution context of upstream messages. In the following example, requests to jsonPublisher are performed on backgroundQueue, but elements received from it are performed on RunLoop.main.

let ioPerformingPublisher == // Some publisher.
let uiUpdatingSubscriber == // Some subscriber that updates the UI.

    .subscribe(on: backgroundQueue)
    .receiveOn(on: RunLoop.main)

Beta Software

This documentation contains preliminary information about an API or technology in development. This information is subject to change, and software implemented according to this documentation should be tested with final operating system software.

Learn more about using Apple's beta software