이니셜라이저는 두 개의 인자를 받는다.
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
다음과 같은 순서로 코드가 동작한다.
결과적으로 값을 전달받을 때 수행할 클로저를 실행한다.
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
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