This is Understanding Combine, written by Matt Neuburg. It is a work in progress. Corrections and suggestions are greatly appreciated (you can comment here). So are donations; please consider keeping me going by funding this work at Or buy my books: the current editions are iOS 13 Programming Fundamentals with Swift and Programming iOS 13. Thank you!


.timeout (Publishers.Timeout) is sort of the opposite of .debounce: you supply a time interval, and the operator wants each successive value to arrive within that time interval. If it doesn’t, and no .finished completion has been received, the operator terminates the pipeline.

The parameters are (see .delay for more information about the first three):

The time interval that must not elapse after a value arriving without another value arriving from upstream.
The scheduler on which the time interval will be measured.
Optional. You’ll usually omit it.
A function that produces an Error. Optional; if omitted, the operator responds to a timeout by sending a .finished completion.

If you want to produce an Error, it needs to be of the same type as the upstream pipeline. For example, if the upstream pipeline’s Failure type is Never, you can’t supply an error function; to fix that, you’ll use .setFailureType before this operator:

.setFailureType(to: Error.self)
.timeout(0.1, scheduler:DispatchQueue.main) {MyError.oops}

Table of Contents