Last active
July 20, 2019 22:47
-
-
Save cartant/4f09e64fb553b04a2b3b71e3f74631ab to your computer and use it in GitHub Desktop.
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
function instrument<T>(source: Observable<T>) { | |
return new Observable<T>(observer => { | |
console.log("source: subscribing"); | |
const subscription = source | |
.do(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