11.4 · receive(on:), subscribe(on:) and where code runs

Combine does not own threads. A value is delivered on whatever thread produced it, until you say otherwise with a scheduler.

Mental model. A pipeline has no thread of its own. The thread is wherever the value was made; receive(on:) moves everything downstream of it.

Threads and schedulers

Where each stage runs, and how to move it.

  1. What do receive(on:) and subscribe(on:) do, and how do you know which thread a stage runs on? 11.4.1 · L3
    A scheduler (DispatchQueue, OperationQueue, RunLoop, ImmediateScheduler) decides when and where a closure runs. Combine does nothing to threads by default: a…

More in Combine