μ΄λμ
λΌμ΄μ λ λ κ°μ μΈμλ₯Ό λ°λλ€.
λ€λ₯Έ Publisherκ° κ°μ λΌ λκΉμ§ κΈ°μ‘΄ Publisherκ° μμλ₯Ό λ°ννλ λμμ ꡬννκΈ° μν΄ μ¬μ©νλ€.
let sourceSubject = PassthroughSubject<Int, Never>()
let otherSubject = PassthroughSubject<Int, Never>()
// Publishers.PrefixUntilOutput Publisher
Publishers
.PrefixUntilOutput(upstream: sourceSubject, other: otherSubject)
.sink(receiveCompletion: { completion in
switch completion {
case .failure:
print("Combine PrefixUntilOutput Error")
case .finished:
print("Combine PrefixUntilOutput Finish")
}
}, receiveValue: { value in
print("Combine PrefixUntilOutput : \(value)")
})
.store(in: &cancellables)
// prefix Operator
sourceSubject
.prefix(untilOutputFrom: otherSubject)
.sink(receiveCompletion: { completion in
switch completion {
case .failure:
print("Combine PrefixUntilOutput Error")
case .finished:
print("Combine PrefixUntilOutput Finish")
}
}, receiveValue: { value in
print("Combine PrefixUntilOutput : \(value)")
})
.store(in: &cancellables)
// 1
sourceSubject.send(1)
// 2
otherSubject.send(2)
// 3
sourceSubject.send(3)
// Combine PrefixUntilOutput : 1
// Combine PrefixUntilOutput Finish
μ½λλ λ€μκ³Ό κ°μ μμλ‘ λμνλ€.
let sourceSubject = PublishSubject<Int>()
let otherSubject = PublishSubject<Int>()
sourceSubject
.takeUntil(otherSubject)
.subscribe(onNext: { value in
print("RxSwift PrefixUntilOutput : \(value)")
}, onError: { _ in
print("RxSwift PrefixUntilOutput Error")
}, onCompleted: {
print("RxSwift PrefixUntilOutput Finish")
})
.disposed(by: disposeBag)
sourceSubject.onNext(1)
otherSubject.onNext(2)
sourceSubject.onNext(3)
// RxSwift PrefixUntilOutput : 1
// RxSwift PrefixUntilOutput Finish
let sourceProperty = MutableProperty(0)
let otherProperty = MutableProperty(0)
sourceProperty.signal
.take(until: otherProperty.signal.map(value: Void()))
.observe { event in
switch event {
case let .value(value):
print("ReactiveSwift PrefixUntilOutput : \(value)")
case .failed:
print("ReactiveSwift PrefixUntilOutput Error")
case .completed:
print("ReactiveSwift PrefixUntilOutput Finish")
default:
break
}
}
sourceProperty.value = 1
otherProperty.value = 2
sourceProperty.value = 3
// ReactiveSwift PrefixUntilOutput : 1
// ReactiveSwift PrefixUntilOutput Finish