This is Understanding Combine, written by Matt Neuburg. Corrections and suggestions are greatly appreciated (you can comment here). So are donations; please consider keeping me going by funding this work at http://www.paypal.me/mattneub. Or buy my books: the current (and final) editions are iOS 15 Programming Fundamentals with Swift and Programming iOS 14. 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):
_:
scheduler:
options:
customError:
.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}