a scheduler is a context where a process takes place. This context can be a thread, a dispatch queue or similar entities, or even an NSOperation which is used inside the OperationQueueScheduler.
let fruit =Observable<String>.create { observer in observer.onNext("[apple]") sleep(2) observer.onNext("[pineapple]") sleep(2) observer.onNext("[strawberry]") returnDisposables.create() }
fruit .dump() .dumpingSubscription() .disposed(by: _disposeBag)
其中:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
extensionObservableType { funcdump() -> RxSwift.Observable<Self.E> { returnself.do(onNext: { element in let threadName = getThreadName() print("\(secondsElapsed())s | [副作用(do)] \(element) received on \(threadName)") }) }
funcdumpingSubscription() -> Disposable { returnself.subscribe(onNext: { element in let threadName = getThreadName() print("\(secondsElapsed())s | [观察(subscribe)] \(element) received on \(threadName)") }) } }