Created
May 4, 2016 01:31
-
-
Save eddieajau/f2e4e71aa50dfea7374aa33c7301cd4c to your computer and use it in GitHub Desktop.
SafeObserver
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
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