Skip to content

Instantly share code, notes, and snippets.

@eviathan
Last active December 20, 2018 17:04
Show Gist options
  • Save eviathan/258d184a737718c3f5a7a7346947ddb0 to your computer and use it in GitHub Desktop.
Save eviathan/258d184a737718c3f5a7a7346947ddb0 to your computer and use it in GitHub Desktop.
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