Generic Instance Method


Specifies the scheduler on which to receive elements from the publisher.


func receive<S>(on scheduler: S, options: S.SchedulerOptions? = nil) -> Publishers.ReceiveOn<Self, S> where S : Scheduler



The scheduler the publisher uses for element delivery.


Scheduler options used to customize element delivery.

Return Value

A publisher that delivers elements using the specified scheduler.


You use the receive(on:options:) operator to receive results on a specific scheduler, such as performing UI work on the main run loop. In contrast with subscribe(on:options:), which affects upstream messages, receive(on:options:) changes the execution context of downstream messages. In the following example, jsonPublisher uses backgroundQueue to process requests. However, it uses RunLoop.main to send elements to the subscriber, labelUpdater.

let jsonPublisher = MyJSONLoaderPublisher() // Some publisher.
let labelUpdater = MyLabelUpdateSubscriber() // Some subscriber that updates the UI.

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

See Also

Specifying Schedulers

func subscribe<S>(on: S, options: S.SchedulerOptions?) -> Publishers.SubscribeOn<Self, S>

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