Last active
December 20, 2018 17:04
-
-
Save eviathan/258d184a737718c3f5a7a7346947ddb0 to your computer and use it in GitHub Desktop.
# [Empty, Never & Throw](http://reactivex.io/documentation/operators/empty-never-throw.html)
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
let next = { print($0) } | |
let error = { print($0) } | |
let completed = { print("Completed") } | |
let disposed = { print("Disposed") } | |
// Empty | |
let emptyObservable = Observable<Int>.empty() | |
emptyObservable.subscribe(onNext: next, onError: error, onCompleted: completed, onDisposed: disposed) | |
// Never | |
let neverObservable = Observable<Int>.never() | |
neverObservable.subscribe(onNext: next, onError: error, onCompleted: completed, onDisposed: disposed) | |
// Throw | |
struct RuntimeError: Error { | |
let message: String | |
init(_ message: String) { | |
self.message = message | |
} | |
public var localizedDescription: String { | |
return message | |
} | |
} | |
let throwObservable = Observable<Int>.error(RuntimeError("Something dun Broke!")) | |
throwObservable.subscribe(onNext: next, onError: error, onCompleted: completed, onDisposed: disposed) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment