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μ μ½λλ₯Ό μ€ννλ©΄
sourceSubjectSubjectμ 1μ κ°μ μ λ¬νμ§λ§,otherSubjectκ° μμλ₯Ό λ°νν μ μ΄ μμΌλ―λ‘ μ λ¬λ κ°μ 무μνλ€.2μ μ½λλ₯Ό μ€ννλ©΄
otherSubjectSubjectμ 2μ κ°μ μ λ¬νλ€.3μ μ½λλ₯Ό μ€ννλ©΄
sourceSubjectSubjectμ 3μ κ°μ μ λ¬νλ©°,otherSubjectκ° μμλ₯Ό λ°νν μ μ΄ μμΌλ―λ‘ μ λ¬λ κ°μ λ°ννλ€.
κ²°κ³Όμ μΌλ‘ κ°μ μ λ¬λ°μ λ μνν ν΄λ‘μ λ₯Ό μ€ννλ€.
RxSwift
skipUntil μ€νΌλ μ΄ν°λ₯Ό μ¬μ©νμ¬ κ΅¬νν μ μλ€.
ReactiveSwift
skip μ€νΌλ μ΄ν°λ₯Ό μ¬μ©νμ¬ κ΅¬νν μ μλ€.
μ°Έκ³
Last updated
Was this helpful?