Skip to content

Instantly share code, notes, and snippets.

@eddieajau
Created May 4, 2016 01:31
Show Gist options
  • Save eddieajau/f2e4e71aa50dfea7374aa33c7301cd4c to your computer and use it in GitHub Desktop.
Save eddieajau/f2e4e71aa50dfea7374aa33c7301cd4c to your computer and use it in GitHub Desktop.
SafeObserver
class SafeObserver {
constructor(private _next: (value: any) => void = () => {},
public error: (errorValue: any) => void = (e: any) => { throw e; },
private _complete: (completeValue?: any) => void = () => {}) {}
public next(value: any) {
try {
this._next(value);
}
catch (e) {
this.error(e);
}
}
public complete(value: any) {
try {
this._complete(value);
}
catch (e) {
this.error(e);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment