이니셜라이저는 다섯 개의 인자를 받는다.
상위 Publisher에 주어진 시간 동안 요소가 전달되지 않을 때 타임아웃이 발생하여 Publisher를 종료한다.
let subject = PassthroughSubject<Int, Error>()
// Publishers.Timeout (customError != nil)
Publishers.Timeout(upstream: subject, interval: .milliseconds(500), scheduler: DispatchQueue.main, options: nil) { error }
.sink(receiveCompletion: { completion in
switch completion {
case .failure:
print("Combine TimeOut Error")
case .finished:
print("Combine TimeOut Finish")
}
}, receiveValue: { value in
print("Combine TimeOut : \(value)")
})
.store(in: &cancellables)
// Combine Timeout Error
// timeout Operator (customError == nil)
subject
.timeout(.milliseconds(500), scheduler: DispatchQueue.main)
.sink(receiveCompletion: { completion in
switch completion {
case .failure:
print("Combine TimeOut Error")
case .finished:
print("Combine TimeOut Finish")
}
}, receiveValue: { value in
print("Combine TimeOut : \(value)")
})
.store(in: &cancellables)
// Combine Timeout Finish
let subject = PublishSubject<Int>()
subject
.timeout(.milliseconds(500), scheduler: MainScheduler.instance)
.subscribe(onNext: { value in
print("RxSwift Timeout : \(value)")
}, onError: { _ in
print("RxSwift Timeout Error")
}, onCompleted: {
print("RxSwift Timeout Finish")
})
.disposed(by: disposeBag)
// RxSwift Timeout Error
let property = MutableProperty<Int>(0)
property.signal
.timeout(after: 0.5, raising: error, on: QueueScheduler.main)
.observe { event in
switch event {
case let .value(value):
print("ReactiveSwift Timeout : \(value)")
case .failed:
print("ReactiveSwift Timeout Error")
case .completed:
print("ReactiveSwift Timeout Finish")
default:
break
}
}
// ReactiveSwift Timeout Error