<!--
{
  "availability" : [
    "iOS: 13.0.0 -",
    "iPadOS: 13.0.0 -",
    "macCatalyst: 13.0.0 -",
    "macOS: 10.15.0 -",
    "tvOS: 13.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 6.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Combine",
  "identifier" : "/documentation/Combine/Publisher/timeout(_:scheduler:options:customError:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Combine"
    ],
    "preciseIdentifier" : "s:7Combine9PublisherPAAE7timeout_9scheduler7options11customErrorAA10PublishersO7TimeoutVy_xqd__G17SchedulerTimeType_6StrideQYd___qd__0J7OptionsQyd__Sg7FailureQzycSgtAA0J0Rd__lF"
  },
  "title" : "timeout(_:scheduler:options:customError:)"
}
-->

# timeout(_:scheduler:options:customError:)

Terminates publishing if the upstream publisher exceeds the specified time interval without producing an element.

```
func timeout<S>(_ interval: S.SchedulerTimeType.Stride, scheduler: S, options: S.SchedulerOptions? = nil, customError: (() -> Self.Failure)? = nil) -> Publishers.Timeout<Self, S> where S : Scheduler
```

## Parameters

`interval`

The maximum time interval the publisher can go without emitting an element, expressed in the time system of the scheduler.

`scheduler`

The scheduler on which to deliver events.

`options`

Scheduler options that customize the delivery of elements.

`customError`

A closure that executes if the publisher times out. The publisher sends the failure returned by this closure to the subscriber as the reason for termination.

## Return Value

A publisher that terminates if the specified interval elapses with no events received from the upstream publisher.

## Discussion

Use [`timeout(_:scheduler:options:customError:)`](/documentation/Combine/Publisher/timeout(_:scheduler:options:customError:)) to terminate a publisher if an element isn’t delivered within a timeout interval you specify.

In the example below, a [`PassthroughSubject`](/documentation/Combine/PassthroughSubject) publishes <doc://com.apple.documentation/documentation/Swift/String> elements and is configured to time out if no new elements are received within its `TIME_OUT` window of 5 seconds. A single value is published after the specified 2-second `WAIT_TIME`, after which no more elements are available; the publisher then times out and completes normally.

```
var WAIT_TIME : Int = 2
var TIMEOUT_TIME : Int = 5

let subject = PassthroughSubject<String, Never>()
let cancellable = subject
    .timeout(.seconds(TIMEOUT_TIME), scheduler: DispatchQueue.main, options: nil, customError:nil)
    .sink(
          receiveCompletion: { print ("completion: \($0) at \(Date())") },
          receiveValue: { print ("value: \($0) at \(Date())") }
     )

DispatchQueue.main.asyncAfter(deadline: .now() + .seconds(WAIT_TIME),
                              execute: { subject.send("Some data - sent after a delay of \(WAIT_TIME) seconds") } )

// Prints: value: Some data - sent after a delay of 2 seconds at 2020-03-10 23:47:59 +0000
//         completion: finished at 2020-03-10 23:48:04 +0000
```

If `customError` is `nil`, the publisher completes normally; if you provide a closure for the `customError` argument, the upstream publisher is instead terminated upon timeout, and the error is delivered to the downstream.

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)