From 4cde7d69ffd90305c30f5cca037cd2c260bcff28 Mon Sep 17 00:00:00 2001 From: freak4pc Date: Sat, 3 Oct 2020 19:07:20 +0300 Subject: [PATCH] Rename `subscribeOn` to `subscribe(on:)` --- RxCocoa/Common/DelegateProxy.swift | 2 +- RxCocoa/Traits/ControlEvent.swift | 4 ++-- RxCocoa/Traits/ControlProperty.swift | 4 ++-- .../SharedSequence/SharedSequence.swift | 4 ++-- RxExample/RxExample/Feedbacks.swift | 2 +- .../RxExample/Observable+Extensions.swift | 2 +- RxSwift/Observables/SubscribeOn.swift | 22 +++++++++++++++++- .../PrimitiveSequence/PrimitiveSequence.swift | 23 ++++++++++++++++++- .../Observable+BlockingTest.swift | 8 +++---- Tests/RxCocoaTests/SharedSequence+Test.swift | 2 +- Tests/RxSwiftTests/CompletableTest.swift | 2 +- Tests/RxSwiftTests/MaybeTest.swift | 2 +- .../Observable+SubscribeOnTests.swift | 12 +++++----- Tests/RxSwiftTests/SingleTest.swift | 2 +- 14 files changed, 66 insertions(+), 25 deletions(-) diff --git a/RxCocoa/Common/DelegateProxy.swift b/RxCocoa/Common/DelegateProxy.swift index 37b02c57..4ef8de73 100644 --- a/RxCocoa/Common/DelegateProxy.swift +++ b/RxCocoa/Common/DelegateProxy.swift @@ -274,7 +274,7 @@ self.result = dispatcher .do(onSubscribed: { weakDelegateProxy?.checkSelectorIsObservable(selector); weakDelegateProxy?.reset() }, onDispose: { weakDelegateProxy?.reset() }) .share() - .subscribeOn(mainScheduler) + .subscribe(on: mainScheduler) } var on: (Event<[Any]>) -> Void { diff --git a/RxCocoa/Traits/ControlEvent.swift b/RxCocoa/Traits/ControlEvent.swift index 4802d739..bea1d83d 100644 --- a/RxCocoa/Traits/ControlEvent.swift +++ b/RxCocoa/Traits/ControlEvent.swift @@ -26,7 +26,7 @@ public protocol ControlEventType : ObservableType { - it delivers events on `MainScheduler.instance`. **The implementation of `ControlEvent` will ensure that sequence of events is being subscribed on main scheduler - (`subscribeOn(ConcurrentMainScheduler.instance)` behavior).** + (`subscribe(on: ConcurrentMainScheduler.instance)` behavior).** **It is the implementor’s responsibility to make sure that all other properties enumerated above are satisfied.** @@ -45,7 +45,7 @@ public struct ControlEvent : ControlEventType { /// - parameter events: Observable sequence that represents events. /// - returns: Control event created with a observable sequence of events. public init(events: Ev) where Ev.Element == Element { - self.events = events.subscribeOn(ConcurrentMainScheduler.instance) + self.events = events.subscribe(on: ConcurrentMainScheduler.instance) } /// Subscribes an observer to control events. diff --git a/RxCocoa/Traits/ControlProperty.swift b/RxCocoa/Traits/ControlProperty.swift index f77f46ee..3068afbf 100644 --- a/RxCocoa/Traits/ControlProperty.swift +++ b/RxCocoa/Traits/ControlProperty.swift @@ -30,7 +30,7 @@ public protocol ControlPropertyType : ObservableType, ObserverType { - it delivers events on `MainScheduler.instance` **The implementation of `ControlProperty` will ensure that sequence of values is being subscribed on main scheduler - (`subscribeOn(ConcurrentMainScheduler.instance)` behavior).** + (`subscribe(on: ConcurrentMainScheduler.instance)` behavior).** **It is implementor's responsibility to make sure that that all other properties enumerated above are satisfied.** @@ -53,7 +53,7 @@ public struct ControlProperty : ControlPropertyType { /// - returns: Control property created with a observable sequence of values and an observer that enables binding values /// to property. public init(values: Values, valueSink: Sink) where Element == Values.Element, Element == Sink.Element { - self.values = values.subscribeOn(ConcurrentMainScheduler.instance) + self.values = values.subscribe(on: ConcurrentMainScheduler.instance) self.valueSink = valueSink.asObserver() } diff --git a/RxCocoa/Traits/SharedSequence/SharedSequence.swift b/RxCocoa/Traits/SharedSequence/SharedSequence.swift index 8534e03f..4db2ee49 100644 --- a/RxCocoa/Traits/SharedSequence/SharedSequence.swift +++ b/RxCocoa/Traits/SharedSequence/SharedSequence.swift @@ -103,7 +103,7 @@ extension SharedSequence { - returns: An observable sequence with no elements. */ public static func empty() -> SharedSequence { - SharedSequence(raw: Observable.empty().subscribeOn(SharingStrategy.scheduler)) + SharedSequence(raw: Observable.empty().subscribe(on: SharingStrategy.scheduler)) } /** @@ -122,7 +122,7 @@ extension SharedSequence { - returns: An observable sequence containing the single specified element. */ public static func just(_ element: Element) -> SharedSequence { - SharedSequence(raw: Observable.just(element).subscribeOn(SharingStrategy.scheduler)) + SharedSequence(raw: Observable.just(element).subscribe(on: SharingStrategy.scheduler)) } /** diff --git a/RxExample/RxExample/Feedbacks.swift b/RxExample/RxExample/Feedbacks.swift index 81a8b2c6..8dba562a 100644 --- a/RxExample/RxExample/Feedbacks.swift +++ b/RxExample/RxExample/Feedbacks.swift @@ -271,7 +271,7 @@ extension Observable { .observe(on:scheduler.async) // subscribe on is here because side-effects also need to be cancelable // (smooths out any glitches caused by start-cancel immediately) - .subscribeOn(scheduler.async) + .subscribe(on: scheduler.async) } } diff --git a/RxExample/RxExample/Observable+Extensions.swift b/RxExample/RxExample/Observable+Extensions.swift index 42c3ef08..733c93bb 100644 --- a/RxExample/RxExample/Observable+Extensions.swift +++ b/RxExample/RxExample/Observable+Extensions.swift @@ -52,7 +52,7 @@ extension ObservableType where Element == Any { }, onSubscribed: { replaySubject.onNext(initialState) }) - .subscribeOn(scheduler) + .subscribe(on: scheduler) .startWith(initialState) .observe(on:scheduler) } diff --git a/RxSwift/Observables/SubscribeOn.swift b/RxSwift/Observables/SubscribeOn.swift index 383be4f0..e8e41d9c 100644 --- a/RxSwift/Observables/SubscribeOn.swift +++ b/RxSwift/Observables/SubscribeOn.swift @@ -7,6 +7,25 @@ // extension ObservableType { + /** + Wraps the source sequence in order to run its subscription and unsubscription logic on the specified + scheduler. + + This operation is not commonly used. + + This only performs the side-effects of subscription and unsubscription on the specified scheduler. + + In order to invoke observer callbacks on a `scheduler`, use `observeOn`. + + - seealso: [subscribeOn operator on reactivex.io](http://reactivex.io/documentation/operators/subscribeon.html) + + - parameter scheduler: Scheduler to perform subscription and unsubscription actions on. + - returns: The source sequence whose subscriptions and unsubscriptions happen on the specified scheduler. + */ + public func subscribe(on scheduler: ImmediateSchedulerType) + -> Observable { + SubscribeOn(source: self, scheduler: scheduler) + } /** Wraps the source sequence in order to run its subscription and unsubscription logic on the specified @@ -23,9 +42,10 @@ extension ObservableType { - parameter scheduler: Scheduler to perform subscription and unsubscription actions on. - returns: The source sequence whose subscriptions and unsubscriptions happen on the specified scheduler. */ + @available(*, deprecated, renamed: "subscribe(on:)") public func subscribeOn(_ scheduler: ImmediateSchedulerType) -> Observable { - SubscribeOn(source: self, scheduler: scheduler) + subscribe(on: scheduler) } } diff --git a/RxSwift/Traits/PrimitiveSequence/PrimitiveSequence.swift b/RxSwift/Traits/PrimitiveSequence/PrimitiveSequence.swift index eb387487..bef83aa2 100644 --- a/RxSwift/Traits/PrimitiveSequence/PrimitiveSequence.swift +++ b/RxSwift/Traits/PrimitiveSequence/PrimitiveSequence.swift @@ -139,9 +139,30 @@ extension PrimitiveSequence { - parameter scheduler: Scheduler to perform subscription and unsubscription actions on. - returns: The source sequence whose subscriptions and unsubscriptions happen on the specified scheduler. */ + public func subscribe(on scheduler: ImmediateSchedulerType) + -> PrimitiveSequence { + PrimitiveSequence(raw: self.source.subscribe(on: scheduler)) + } + + /** + Wraps the source sequence in order to run its subscription and unsubscription logic on the specified + scheduler. + + This operation is not commonly used. + + This only performs the side-effects of subscription and unsubscription on the specified scheduler. + + In order to invoke observer callbacks on a `scheduler`, use `observeOn`. + + - seealso: [subscribeOn operator on reactivex.io](http://reactivex.io/documentation/operators/subscribeon.html) + + - parameter scheduler: Scheduler to perform subscription and unsubscription actions on. + - returns: The source sequence whose subscriptions and unsubscriptions happen on the specified scheduler. + */ + @available(*, deprecated, renamed: "subscribe(on:)") public func subscribeOn(_ scheduler: ImmediateSchedulerType) -> PrimitiveSequence { - PrimitiveSequence(raw: self.source.subscribeOn(scheduler)) + subscribe(on: scheduler) } /** diff --git a/Tests/RxBlockingTests/Observable+BlockingTest.swift b/Tests/RxBlockingTests/Observable+BlockingTest.swift index 4081c688..b2b25917 100644 --- a/Tests/RxBlockingTests/Observable+BlockingTest.swift +++ b/Tests/RxBlockingTests/Observable+BlockingTest.swift @@ -48,7 +48,7 @@ extension ObservableBlockingTest { let scheduler = ConcurrentDispatchQueueScheduler(qos: .default) func operation1()->Observable{ - return Observable.of(1, 2).subscribeOn(scheduler) + return Observable.of(1, 2).subscribe(on: scheduler) } let a = try! operation1().toBlocking().toArray() @@ -105,7 +105,7 @@ extension ObservableBlockingTest { let scheduler = ConcurrentDispatchQueueScheduler(qos: .default) func operation1()->Observable{ - return Observable.just(1).subscribeOn(scheduler) + return Observable.just(1).subscribe(on: scheduler) } let a = try! operation1().toBlocking().first() @@ -162,7 +162,7 @@ extension ObservableBlockingTest { let scheduler = ConcurrentDispatchQueueScheduler(qos: .background) func operation1()->Observable{ - return Observable.just(1).subscribeOn(scheduler) + return Observable.just(1).subscribe(on: scheduler) } let a = try! operation1().toBlocking().last() @@ -310,7 +310,7 @@ extension ObservableBlockingTest { let scheduler = ConcurrentDispatchQueueScheduler(qos: .default) func operation1()->Observable{ - return Observable.just(1).subscribeOn(scheduler) + return Observable.just(1).subscribe(on: scheduler) } let a = try! operation1().toBlocking().single() diff --git a/Tests/RxCocoaTests/SharedSequence+Test.swift b/Tests/RxCocoaTests/SharedSequence+Test.swift index d9dc64b2..e2406f47 100644 --- a/Tests/RxCocoaTests/SharedSequence+Test.swift +++ b/Tests/RxCocoaTests/SharedSequence+Test.swift @@ -22,7 +22,7 @@ class SharedSequenceTest: RxTest { // test helpers that make sure that resulting driver operator honors definition // * only one subscription is made and shared - shareReplay(1) -// * subscription is made on main thread - subscribeOn(ConcurrentMainScheduler.instance) +// * subscription is made on main thread - subscribe(on: ConcurrentMainScheduler.instance) // * events are observed on main thread - observe(on:MainScheduler.instance) // * it can't error out - it needs to have catch somewhere extension SharedSequenceTest { diff --git a/Tests/RxSwiftTests/CompletableTest.swift b/Tests/RxSwiftTests/CompletableTest.swift index 87778342..e2289574 100644 --- a/Tests/RxSwiftTests/CompletableTest.swift +++ b/Tests/RxSwiftTests/CompletableTest.swift @@ -260,7 +260,7 @@ extension CompletableTest { let scheduler = TestScheduler(initialClock: 0) let res = scheduler.start { - Completable.empty().subscribeOn(scheduler) + Completable.empty().subscribe(on: scheduler) } XCTAssertEqual(res.events, [ diff --git a/Tests/RxSwiftTests/MaybeTest.swift b/Tests/RxSwiftTests/MaybeTest.swift index 55e0018d..bd474d91 100644 --- a/Tests/RxSwiftTests/MaybeTest.swift +++ b/Tests/RxSwiftTests/MaybeTest.swift @@ -337,7 +337,7 @@ extension MaybeTest { let scheduler = TestScheduler(initialClock: 0) let res = scheduler.start { - Maybe.just(1).subscribeOn(scheduler) + Maybe.just(1).subscribe(on: scheduler) } XCTAssertEqual(res.events, [ diff --git a/Tests/RxSwiftTests/Observable+SubscribeOnTests.swift b/Tests/RxSwiftTests/Observable+SubscribeOnTests.swift index 3f113c3a..8a08061c 100644 --- a/Tests/RxSwiftTests/Observable+SubscribeOnTests.swift +++ b/Tests/RxSwiftTests/Observable+SubscribeOnTests.swift @@ -28,7 +28,7 @@ extension ObservableSubscribeOnTest { } let res = scheduler.start { - xs.subscribeOn(scheduler) + xs.subscribe(on: scheduler) } XCTAssertEqual(res.events, [ @@ -47,7 +47,7 @@ extension ObservableSubscribeOnTest { ]) let res = scheduler.start { - xs.subscribeOn(scheduler) + xs.subscribe(on: scheduler) } XCTAssertEqual(res.events, [ @@ -67,7 +67,7 @@ extension ObservableSubscribeOnTest { ]) let res = scheduler.start { - xs.subscribeOn(scheduler) + xs.subscribe(on: scheduler) } XCTAssertEqual(res.events, [ @@ -88,7 +88,7 @@ extension ObservableSubscribeOnTest { ]) let res = scheduler.start { - xs.subscribeOn(scheduler) + xs.subscribe(on: scheduler) } XCTAssertEqual(res.events, [ @@ -103,13 +103,13 @@ extension ObservableSubscribeOnTest { #if TRACE_RESOURCES func testSubscribeOnSerialReleasesResourcesOnComplete() { let testScheduler = TestScheduler(initialClock: 0) - _ = Observable.just(1).subscribeOn(testScheduler).subscribe() + _ = Observable.just(1).subscribe(on: testScheduler).subscribe() testScheduler.start() } func testSubscribeOnSerialReleasesResourcesOnError() { let testScheduler = TestScheduler(initialClock: 0) - _ = Observable.error(testError).subscribeOn(testScheduler).subscribe() + _ = Observable.error(testError).subscribe(on: testScheduler).subscribe() testScheduler.start() } #endif diff --git a/Tests/RxSwiftTests/SingleTest.swift b/Tests/RxSwiftTests/SingleTest.swift index ccb2d814..004cf4b3 100644 --- a/Tests/RxSwiftTests/SingleTest.swift +++ b/Tests/RxSwiftTests/SingleTest.swift @@ -274,7 +274,7 @@ extension SingleTest { let scheduler = TestScheduler(initialClock: 0) let res = scheduler.start { - Single.just(1).subscribeOn(scheduler) + Single.just(1).subscribe(on: scheduler) } XCTAssertEqual(res.events, [