μ λ€λ¦ ꡬ쑰체 | Publisherμ μ΄λ²€νΈκ° λ°μν λ νΉμ ν΄λ‘μ λ₯Ό μννλ Publisher
μ΄λμ
λΌμ΄μ λ μ¬μ― κ°μ μΈμλ₯Ό λ°λλ€.
upstream
: μμμ νλ₯΄λ Publisher
receiveSubscription
: Publisherκ° μμ Publisherλ‘λΆν° ꡬλ
μ μ λ¬λ°μ λ μνν ν΄λ‘μ . κΈ°λ³Έκ°μ nil
receiveOutput
: Publisherκ° μμ Publisherλ‘λΆν° κ°μ μ λ¬λ°μ λ μνν ν΄λ‘μ . κΈ°λ³Έκ°μ nil
receiveCompletion
: Publisherκ° μμ Publisherλ‘λΆν° μλ£λ₯Ό μ λ¬λ°μ λ μνν ν΄λ‘μ . κΈ°λ³Έκ°μ nil
receiveCancel
: νμ 리μλ²κ° λ°νμ μ·¨μν λ μνν ν΄λ‘μ . κΈ°λ³Έκ°μ nil
receiveRequest
: Publisherκ° λ λ§μ μμλ₯Ό μν΄ μμ²μ μ λ¬λ°μ λ μνν ν΄λ‘μ . κΈ°λ³Έκ°μ nil
μ€νΈλ¦Όμ μλͺ
μ£ΌκΈ° λμ λ°μνλ μ¬λ¬ μ΄λ²€νΈμμ μ€νν μ‘μ
μ λ±λ‘νλ€.
νΉμ μ΄λ²€νΈκ° λ°μν λ νΉμ μμ
μ μννκΈ° μν΄ μ¬μ©ν μ μλ€.
Publisherμ μλͺ
μ£ΌκΈ°λ₯Ό μ΄ν΄νκΈ° μν΄ μ¬μ©ν μ μλ€.
sink
λ Subscriberμ λν μ€νΌλ μ΄ν°κ³ , handleEvents
λ Publisherμ λν μ€νΌλ μ΄ν°λ€.
sink
λ Subscriberμ ꡬλ
μ μν΄ μ΅μ’
μ μΌλ‘ λ°νλ μ΄λ²€νΈμ λν΄ λμνλ€.
handleEvents
λ ꡬλ
μ μν΄ μμ Publisherκ° λ°ννλ μ΄λ²€νΈμ λν΄ λμνλ€.
handleEvents
μ€νΌλ μ΄ν°μ κ΄λ ¨μ΄ μλ€.
// Publishers.HandleEvents Publisher
Publishers
.HandleEvents(upstream: Just(Void()),
receiveSubscription: { _ in print("Combine HandleEvents ReceiveSubscription") },
receiveOutput: { print("Combine HandleEvents ReceiveOutput") },
receiveCompletion: { _ in print("Combine HandleEvents ReceiveCompletion") },
receiveCancel: { print("Combine HandleEvents ReceiveCancel") },
receiveRequest: { _ in print("Combine HandleEvents ReceiveRequest") })
.sink(receiveCompletion: { completion in
switch completion {
case .failure:
print("Combine HandleEvents Error")
case .finished:
print("Combine HandleEvents Finish")
}
}, receiveValue: {
print("Combine HandleEvents")
})
.store(in: &cancellables)
// handleEvents Operator
Just(Void())
.handleEvents(receiveSubscription: { _ in print("Combine HandleEvents ReceiveSubscription") },
receiveOutput: { print("Combine HandleEvents ReceiveOutput") },
receiveCompletion: { _ in print("Combine HandleEvents ReceiveCompletion") },
receiveCancel: { print("Combine HandleEvents ReceiveCancel") },
receiveRequest: { _ in print("Combine HandleEvents ReceiveRequest") })
.sink(receiveCompletion: { completion in
switch completion {
case .failure:
print("Combine HandleEvents Error")
case .finished:
print("Combine HandleEvents Finish")
}
}, receiveValue: {
print("Combine HandleEvents")
})
.store(in: &cancellables)
// Combine HandleEvents Receive Request
// Combine HandleEvents Receive Subscription
// Combine HandleEvents Receive Output
// Combine HandleEvents
// Combine HandleEvents Receive Completion
// Combine HandleEvents Finish
κ²°κ³Όλ₯Ό ν΅ν΄ Publisherλ μλ¬λ₯Ό λ΄μ§ μλ κ²½μ° λ€μκ³Ό κ°μ μμλ‘ λμνλ€λ κ²μ μ μ μλ€.
Publisher : Receive Request
Publisher : Receive Subscription
Publisher : Receive Output
Subscriber : Receive Value
Publisher : Receive Completion
Subscriber : Receive Finished
RxSwift
do
μ€νΌλ μ΄ν°λ₯Ό μ¬μ©νμ¬ κ΅¬νν μ μλ€.
Observable.just(Void())
.do(onNext: { print("RxSwift HandleEvents OnNext") },
afterNext: { print("RxSwift HandleEvents AfterNext") },
onError: { _ in print("RxSwift HandleEvents OnError") },
afterError: { _ in print("RxSwift HandleEvents AfterError") },
onCompleted: { print("RxSwift HandleEvents OnCompleted") },
afterCompleted: { print("RxSwift HandleEvents AfterCompleted") },
onSubscribe: { print("RxSwift HandleEvents OnSubscribe") },
onSubscribed: { print("RxSwift HandleEvents OnSubscribed") },
onDispose: { print("RxSwift HandleEvents OnDispose") })
.subscribe(onNext: {
print("RxSwift HandleEvents")
}, onError: { _ in
print("RxSwift HandleEvents Error")
}, onCompleted: {
print("RxSwift HandleEvents Finish")
})
.disposed(by: disposeBag)
// RxSwift HandleEvents OnSubscribe
// RxSwift HandleEvents OnNext
// RxSwift HandleEvents
// RxSwift HandleEvents AfterNext
// RxSwift HandleEvents OnCompleted
// RxSwift HandleEvents Finish
// RxSwift HandleEvents AfterCompleted
// RxSwift HandleEvents OnSubscribed
// RxSwift HandleEvents OnDispose
ReactiveSwift
on
μ€νΌλ μ΄ν°λ₯Ό μ¬μ©νμ¬ κ΅¬νν μ μλ€.
SignalProducer(value: Void())
.on(starting: { print("ReactiveSwift HandleEvents Starting") },
started: { print("ReactiveSwift HandleEvents Started") },
event: { _ in print("ReactiveSwift HandleEvents Event") },
failed: { _ in print("ReactiveSwift HandleEvents Failed") },
completed: { print("ReactiveSwift HandleEvents Completed") },
interrupted: { print("ReactiveSwift HandleEvents Interrupted") },
terminated: { print("ReactiveSwift HandleEvents Terminated") },
disposed: { print("ReactiveSwift HandleEvents Dispose") },
value: { print("ReactiveSwift HandleEvents Value") })
.start { event in
switch event {
case .value:
print("ReactiveSwift HandleEvents")
case .failed:
print("ReactiveSwift HandleEvents Error")
case .completed:
print("ReactiveSwift HandleEvents Finish")
default:
break
}
}
// ReactiveSwift HandleEvents Starting
// ReactiveSwift HandleEvents Event
// ReactiveSwift HandleEvents Value
// ReactiveSwift HandleEvents
// ReactiveSwift HandleEvents Event
// ReactiveSwift HandleEvents Completed
// ReactiveSwift HandleEvents Terminated
// ReactiveSwift HandleEvents Finish
// ReactiveSwift HandleEvents Dispose
// ReactiveSwift HandleEvents Started
μ°Έκ³
ReactiveX - Operators - Do