Publishers.PrefixUntilOutput
μ λ€λ¦ ꡬ쑰체
μ΄λμ λΌμ΄μ λ λ κ°μ μΈμλ₯Ό λ°λλ€.
upstream: μμμ νλ₯΄λ Publisherother: 첫 μΆλ ₯μ΄upstreamPublisherλ₯Ό μ’ λ£νκ² νλ Publisher
λ€λ₯Έ Publisherκ° κ°μ λΌ λκΉμ§ κΈ°μ‘΄ Publisherκ° μμλ₯Ό λ°ννλ λμμ ꡬννκΈ° μν΄ μ¬μ©νλ€.
prefix μ€νΌλ μ΄ν°μ κ΄λ ¨μ΄ μλ€.
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μ½λλ λ€μκ³Ό κ°μ μμλ‘ λμνλ€.
1μ μ½λλ₯Ό μ€ννλ©΄
sourceSubjectμ 1μ κ°μ μ λ¬νλ©°,otherSubjectκ° κ°μ λ°νν μ μ΄ μμΌλ―λ‘ κ·Έλλ‘ 1μ κ°μ λΈλ€.2μ μ½λλ₯Ό μ€ννλ©΄
otherSubjectμ 2μ κ°μ μ λ¬νλ€. μ΄ λsourceSubjectλ λ€λ₯Έ Publisherκ° κ°μ μ λ¬λ°μμΌλ―λ‘ μ’ λ£νλ€.3μ μ½λλ₯Ό μ€ννλ©΄
sourceSubjectμ 3μ κ°μ μ λ¬νλ€. νμ§λ§sourceSubjectλ 4μ μ½λμ μ€νμ μν΄ μ΄λ―Έ μ’ λ£νμμΌλ―λ‘ ν¨λ ₯μ΄ μλ€.
RxSwift
takeUntil μ€νΌλ μ΄ν°λ₯Ό μ¬μ©νμ¬ κ΅¬νν μ μλ€.
ReactiveSwift
take μ€νΌλ μ΄ν°λ₯Ό μ¬μ©νμ¬ κ΅¬νν μ μλ€.
μ°Έκ³
Last updated
Was this helpful?