Publishers.Breakpoint
์ ๋ค๋ฆญ ๊ตฌ์กฐ์ฒด | ์ ๊ณต๋ ํด๋ก์ ๊ฐ ๋๋ฒ๊ฑฐ์์ ๊ทธ ํ๋ก์ธ์ค๋ฅผ ์ค๋จํ๋ ๊ฒ์ ํ์๋ก ํ ๋ ๋๋ฒ๊ฑฐ ์๊ทธ๋์ ์ผ์ผํค๋ Publisher
์ด๋์ ๋ผ์ด์ ๋ ๋ค ๊ฐ์ ์ธ์๋ฅผ ๋ฐ๋๋ค.
upstream
: ์์์ ํ๋ฅด๋ PublisherreceiveSubscription
: Publisher๊ฐ ๊ตฌ๋ ์ ์ ๋ฌ๋ฐ์ ๋ ์คํ๋๋ฉฐ, true ๊ฐ์ ๋ฐํํ์ฌ ๋๋ฒ๊ฑฐ ์๊ทธ๋์ ์ผ์ผํฌ ์ ์๋ ํด๋ก์ receiveOutput
: Publisher๊ฐ ์์ Publisher๋ก๋ถํฐ ์ถ๋ ฅ์ ์ ๋ฌ๋ฐ์ ๋ ์คํ๋๋ฉฐ, true ๊ฐ์ ๋ฐํํ์ฌ ๋๋ฒ๊ฑฐ ์๊ทธ๋์ ์ผ์ผํฌ ์ ์๋ ํด๋ก์ receiveCompletion
: Publisher๊ฐ ์๋ฃ๋ฅผ ์ ๋ฌ๋ฐ์ ๋ ์คํ๋๋ฉฐ, true ๊ฐ์ ๋ฐํํ์ฌ ๋๋ฒ๊ฑฐ ์๊ทธ๋์ ์ผ์ผํฌ ์ ์๋ ํด๋ก์
handleEvents
์ ๊ฐ์ ์์ ์ ๋์ํ๋ ํด๋ก์ ๊ฐ true๋ฅผ ๋ฐํํ๊ฒ ํ๋ฉด ํด๋น ์ด๋ฒคํธ ์์ ์์ ๋๋ฒ๊ฑฐ ์๊ทธ๋์ ์ผ์ผํฌ ์ ์๋ค.
breakpoint
๋ฐ breakpointOnError
์คํผ๋ ์ดํฐ์ ๊ด๋ จ์ด ์๋ค.
// 1. Publishers.Breakpoint Publisher
Publishers.Breakpoint(upstream: Just(Void()),
receiveSubscription: { _ in true },
receiveOutput: { _ in true },
receiveCompletion: { _ in true })
.sink(receiveCompletion: { completion in
switch completion {
case .failure:
print("Combine Breakpoint Error")
case .finished:
print("Combine Breakpoint Finish")
}
}, receiveValue: {
print("Combine Breakpoint")
})
.store(in: &cancellables)
// 2. breakpoint Operator
Just(Void())
.breakpoint(receiveSubscription: { _ in true },
receiveOutput: { _ in true },
receiveCompletion: { _ in true })
.sink(receiveCompletion: { completion in
switch completion {
case .failure:
print("Combine Breakpoint Error")
case .finished:
print("Combine Breakpoint Finish")
}
}, receiveValue: {
print("Combine Breakpoint")
})
.store(in: &cancellables)
// 3. breakpointOnError Operator
Fail<Void, Error>(error: error)
.breakpointOnError()
.sink(receiveCompletion: { completion in
switch completion {
case .failure:
print("Combine Breakpoint Error")
case .finished:
print("Combine Breakpoint Finish")
}
}, receiveValue: {
print("Combine Breakpoint")
})
.store(in: &cancellables)
1๊ณผ 2์ ์ฝ๋๋ ๊ตฌ๋ , ๊ฐ ๋ฐํ, ์๋ฃ ์ด๋ฒคํธ๊ฐ ์ผ์ด๋ ๋ ๋๋ฒ๊ฑฐ ์๊ทธ๋์ ์ผ์ผํจ๋ค.
3์ ์ฝ๋๋ ์์ Publisher๊ฐ ์๋ฌ๋ฅผ ๋ด๋ฏ๋ก breakpointOnError
์ ์ํด ๋๋ฒ๊ฑฐ ์๊ทธ๋์ ์ผ์ผํจ๋ค.
RxSwift
ํด๋น ๋์์ ๊ตฌํํ๋ ์คํผ๋ ์ดํฐ๋ฅผ ์ ๊ณตํ์ง ์๋๋ค.
ReactiveSwift
ํด๋น ๋์์ ๊ตฌํํ๋ ์คํผ๋ ์ดํฐ๋ฅผ ์ ๊ณตํ์ง ์๋๋ค.
Last updated
Was this helpful?