Publishers.DropUntilOutput
μ λ€λ¦ ꡬ쑰체 | λ λ²μ§Έ Publisherλ‘λΆν° μμλ₯Ό μ λ¬λ°μ λκΉμ§ μμμ νλ₯΄λ Publisherλ‘λΆν° μμλ₯Ό 무μνλ Publisher
μ΄λμ λΌμ΄μ λ λ κ°μ μΈμλ₯Ό λ°λλ€.
upstream
: μμμ νλ₯΄λ Publisherother
: μ²μ λ°°μΆλλ μμλ₯Ό λͺ¨λν°λ§ν Publisher
other
μμ μμκ° μ²μμΌλ‘ λ°νλκΈ° μ κΉμ§λ upstream
μμ λ°ννλ μμλ₯Ό 무μνλ€.
drop
μ€νΌλ μ΄ν°μ κ΄λ ¨μ΄ μλ€.
let sourceSubject = PassthroughSubject<Int, Never>()
let otherSubject = PassthroughSubject<Int, Never>()
// Publishers.DropUntilOutput Publisher
Publishers
.DropUntilOutput(upstream: sourceSubject, other: otherSubject)
.sink(receiveCompletion: { completion in
switch completion {
case .failure:
print("Combine DropUntilOutput Error")
case .finished:
print("Combine DropUntilOutput Finish")
}
}, receiveValue: { value in
print("Combine DropUntilOutput : \(value)")
})
.store(in: &cancellables)
// drop Operator
sourceSubject
.drop(untilOutputFrom: otherSubject)
.sink(receiveCompletion: { completion in
switch completion {
case .failure:
print("Combine DropUntilOutput Error")
case .finished:
print("Combine DropUntilOutput Finish")
}
}, receiveValue: { value in
print("Combine DropUntilOutput : \(value)")
})
.store(in: &cancellables)
// 1
sourceSubject.send(1)
// 2
otherSubject.send(2)
// 3
sourceSubject.send(3)
// Combine DropUntilOutput : 3
λ€μκ³Ό κ°μ μμλ‘ μ½λκ° λμνλ€.
1μ μ½λλ₯Ό μ€ννλ©΄
sourceSubject
Subjectμ 1μ κ°μ μ λ¬νμ§λ§,otherSubject
κ° μμλ₯Ό λ°νν μ μ΄ μμΌλ―λ‘ μ λ¬λ κ°μ 무μνλ€.2μ μ½λλ₯Ό μ€ννλ©΄
otherSubject
Subjectμ 2μ κ°μ μ λ¬νλ€.3μ μ½λλ₯Ό μ€ννλ©΄
sourceSubject
Subjectμ 3μ κ°μ μ λ¬νλ©°,otherSubject
κ° μμλ₯Ό λ°νν μ μ΄ μμΌλ―λ‘ μ λ¬λ κ°μ λ°ννλ€.
κ²°κ³Όμ μΌλ‘ κ°μ μ λ¬λ°μ λ μνν ν΄λ‘μ λ₯Ό μ€ννλ€.
RxSwift
skipUntil
μ€νΌλ μ΄ν°λ₯Ό μ¬μ©νμ¬ κ΅¬νν μ μλ€.
let sourceSubject = PublishSubject<Int>()
let otherSubject = PublishSubject<Int>()
sourceSubject.skipUntil(otherSubject)
.subscribe(onNext: { value in
print("RxSwift DropUntilOutput : \(value)")
}, onError: { _ in
print("RxSwift DropUntilOutput Error")
}, onCompleted: {
print("RxSwift DropUntilOutput Finish")
})
.disposed(by: disposeBag)
sourceSubject.onNext(1)
otherSubject.onNext(2)
sourceSubject.onNext(3)
// RxSwift DropUntilOutput : 3
ReactiveSwift
skip
μ€νΌλ μ΄ν°λ₯Ό μ¬μ©νμ¬ κ΅¬νν μ μλ€.
let sourceProperty = MutableProperty(0)
let otherProperty = MutableProperty(0)
sourceProperty.signal
.skip(until: otherProperty.signal)
.observe { event in
switch event {
case let .value(value):
print("ReactiveSwift DropUntilOutput : \(value)")
case .failed:
print("ReactiveSwift DropUntilOutput Error")
case .completed:
print("ReactiveSwift DropUntilOutput Finish")
default:
break
}
}
sourceProperty.value = 1
otherProperty.value = 2
sourceProperty.value = 3
// ReactiveSwift DropUntilOutput : 3
// ReactiveSwift DropUntilOutput Finish
μ°Έκ³
Last updated
Was this helpful?