Adds `deferred` to `Driver` unit.
This commit is contained in:
parent
d786b367f1
commit
0b5b9fe97a
|
|
@ -115,7 +115,19 @@ public struct Drive {
|
|||
public static func just<E>(element: E) -> Driver<E> {
|
||||
return Driver(raw: RxSwift.just(element).subscribeOn(ConcurrentMainScheduler.sharedInstance))
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
Returns an observable sequence that invokes the specified factory function whenever a new observer subscribes.
|
||||
|
||||
- parameter observableFactory: Observable factory function to invoke for each observer that subscribes to the resulting sequence.
|
||||
- returns: An observable sequence whose observers trigger an invocation of the given observable factory function.
|
||||
*/
|
||||
@warn_unused_result(message="http://git.io/rxs.uo")
|
||||
public static func deferred<E>(observableFactory: () -> Driver<E>)
|
||||
-> Driver<E> {
|
||||
return Driver(RxSwift.deferred { observableFactory().asObservable() })
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
/**
|
||||
|
|
@ -148,7 +160,19 @@ public struct Drive {
|
|||
public static func just<E>(element: E) -> Driver<E> {
|
||||
return Driver(raw: _just(element).subscribeOn(ConcurrentMainScheduler.sharedInstance))
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
Returns an observable sequence that invokes the specified factory function whenever a new observer subscribes.
|
||||
|
||||
- parameter observableFactory: Observable factory function to invoke for each observer that subscribes to the resulting sequence.
|
||||
- returns: An observable sequence whose observers trigger an invocation of the given observable factory function.
|
||||
*/
|
||||
@warn_unused_result(message="http://git.io/rxs.uo")
|
||||
public static func deferred<E>(observableFactory: () -> Driver<E>)
|
||||
-> Driver<E> {
|
||||
return Driver(_deferred { observableFactory().asObservable() })
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@warn_unused_result(message="http://git.io/rxs.uo")
|
||||
|
|
@ -174,5 +198,10 @@ func _never<E>() -> Observable<E> {
|
|||
func _just<E>(element: E) -> Observable<E> {
|
||||
return just(element)
|
||||
}
|
||||
|
||||
func _deferred<E>(observableFactory: () -> Observable<E>)
|
||||
-> Observable<E> {
|
||||
return deferred(observableFactory)
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -293,6 +293,26 @@ extension DriverTest {
|
|||
}
|
||||
}
|
||||
|
||||
// MARK: deferred
|
||||
extension DriverTest {
|
||||
func testAsDriver_deferred() {
|
||||
let hotObservable = BackgroundThreadPrimitiveHotObservable<Int>()
|
||||
let driver = Drive.deferred { hotObservable.asDriver(onErrorJustReturn: -1) }
|
||||
|
||||
let results = subscribeTwiceOnBackgroundSchedulerAndOnlyOneSubscription(driver) {
|
||||
XCTAssertTrue(hotObservable.subscriptions == [SubscribedToHotObservable])
|
||||
|
||||
hotObservable.on(.Next(1))
|
||||
hotObservable.on(.Next(2))
|
||||
hotObservable.on(.Error(testError))
|
||||
|
||||
XCTAssertTrue(hotObservable.subscriptions == [UnsunscribedFromHotObservable])
|
||||
}
|
||||
|
||||
XCTAssertEqual(results, [1, 2, -1])
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: map
|
||||
extension DriverTest {
|
||||
func testAsDriver_map() {
|
||||
|
|
@ -314,7 +334,6 @@ extension DriverTest {
|
|||
|
||||
XCTAssertEqual(results, [2, 3, 0])
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// MARK: filter
|
||||
|
|
|
|||
Loading…
Reference in New Issue