Last active
December 19, 2019 17:08
-
-
Save sidepelican/4e2d496e482572603362b67c05b5d1be to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import RxSwift | |
import RxCocoa | |
import UIKit | |
extension SharedSequence { | |
func assertStartWithEvent(file: StaticString = #file, line: UInt = #line) -> Self { | |
let deadline = Observable<Element>.create { observer -> Disposable in | |
fatalError("Event didn't come immediately after subscribe.", file: file, line: line) | |
} | |
.delaySubscription(.nanoseconds(0), scheduler: SharingStrategy.scheduler) | |
return asObservable() | |
.amb(deadline) | |
.asSharedSequence(sharingStrategy: SharingStrategy.self, onErrorRecover: { _ in fatalError("Never come here") }) | |
} | |
} | |
class ViewController: UIViewController { | |
override func viewDidLoad() { | |
super.viewDidLoad() | |
let driverWithInitialValue = Driver.just(1) | |
_ = driverWithInitialValue | |
.assertStartWithEvent() | |
.drive() | |
let relay = PublishRelay<Int>() | |
let driverWithNoReplay = relay.asDriver(onErrorJustReturn: -1) | |
_ = driverWithNoReplay | |
.assertStartWithEvent() | |
.drive() | |
relay.accept(1) | |
DispatchQueue.main.async { | |
relay.accept(1) | |
} | |
print("hi") | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment