Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save LayZeeDK/4f03f0a904663d4a10709523938b38c4 to your computer and use it in GitHub Desktop.
Save LayZeeDK/4f03f0a904663d4a10709523938b38c4 to your computer and use it in GitHub Desktop.
RxJS ≥6 version
function instrument<T>(source: Observable<T>) {
return new Observable<T>(observer => {
console.log("source: subscribing");
const subscription = source.pipe(
tap(value => console.log(`source: ${value}`)),
).subscribe(observer);
return () => {
subscription.unsubscribe();
console.log("source: unsubscribed");
};
});
}
function observer<T>(name: string) {
return {
next: (value: T) => console.log(`observer ${name}: ${value}`),
complete: () => console.log(`observer ${name}: complete`)
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment