Just
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
final private class Just<Element>: Producer<Element> {
private let _element: Element
init(element: Element) {
self._element = element
}
override func subscribe<Observer: ObserverType>(_ observer: Observer) -> Disposable where Observer.Element == Element {
// emit `next` them `complete` event
observer.on(.next(self._element))
observer.on(.completed)
// return a `EmptyDisposable`
return Disposables.create()
}
}
直接重写producer的subscribe方法
注:文中源码来自RxSwift