μ λ€λ¦ ꡬ쑰체 | μ€ν¨ν μμ Publisherμ λνμ¬ κ΅¬λ
μ λ€μ μμ±νλ κ²μ μλνλ Publisher
μ΄λμ
λΌμ΄μ λ λ κ°μ μΈμλ₯Ό λ°λλ€.
upstream
: μμμ νλ₯΄λ Publisher
retries
: μ΅λ μ¬μλ νμ. nilμ΄ λ€μ΄κ°λ©΄ μμ Publisherκ° μλ¬λ₯Ό λ΄μ§ μμ λκΉμ§ μ¬μλνλ€.
μλ₯Ό λ€μ΄ νΉμ λ€νΈμν¬ μμ²μ΄ μ±κ³΅ν λκΉμ§ λ€μ μμ²νλ € νλ€λ©΄ μ΄ λμμ μ¬μ©ν μ μλ€.
retry
μ€νΌλ μ΄ν°μ κ΄λ ¨μ΄ μλ€.
// Publishers.Retry Publisher
Publishers.Retry(upstream: Fail<Void, Error>(error: error), retries: 2)
.sink(receiveCompletion: { completion in
switch completion {
case .failure:
print("Combine Retry Error")
case .finished:
print("Combine Retry Finish")
}
}, receiveValue: { value in
print("Combine Retry : \(value)")
})
.store(in: &cancellables)
// retry Operator
Fail<Void, Error>(error: error)
.retry(2)
.sink(receiveCompletion: { completion in
switch completion {
case .failure:
print("Combine Retry Error")
case .finished:
print("Combine Retry Finish")
}
}, receiveValue: { value in
print("Combine Retry : \(value)")
})
.store(in: &cancellables)
// Combine Retry Error
μμ μ½λλ μμ Publisherλ‘ Fail
Publisherλ₯Ό λͺ
μνμλ€.
κ·Έλ¬λ―λ‘ μ²« ꡬλ
μμ μλ¬κ° λ΄λ €μ€κ² λκ³ , μ΄ν λ λ² μ¬μλνλ€.
λ λ²μ μ¬μλμλ λΆκ΅¬νκ³ μλ¬κ° λ΄λ €μ€λ―λ‘ κ²°κ³Όμ μΌλ‘ μλ¬λ₯Ό λΈλ€.
RxSwift
retry
μ€νΌλ μ΄ν°λ₯Ό μ¬μ©νμ¬ κ΅¬νν μ μλ€.
Observable<Void>.error(error)
.retry(2)
.subscribe(onNext: { value in
print("RxSwift Retry : \(value)")
}, onError: { _ in
print("RxSwift Retry Error")
}, onCompleted: {
print("RxSwift Retry Finish")
})
.disposed(by: disposeBag)
// RxSwift Retry Error
ReactiveSwift
retry
μ€νΌλ μ΄ν°λ₯Ό μ¬μ©νμ¬ κ΅¬νν μ μλ€.
SignalProducer<Void, Error>(error: error)
.retry(upTo: 2)
.start { event in
switch event {
case let .value(value):
print("ReactiveSwift Retry : \(value)")
case .failed:
print("ReactiveSwift Retry Error")
case .completed:
print("ReactiveSwift Retry Finish")
default:
break
}
}
// ReactiveSwift Retry Error
μ°Έκ³
ReactiveX - Operators - Retry