Last active
March 26, 2022 11:56
-
-
Save ArtemRomanovsky/3a9c10a647e3058307f568cbf6121479 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
emitValue(observer) { | |
let i = 0; | |
const id = setInterval(() => { | |
observer.next(i++) | |
}, 1000) | |
return () => { clearInterval(id) } | |
} | |
createObservable(emitValueFn) { | |
return { | |
subscribe: emitValueFn, | |
} | |
} | |
const observer = { next: (v) => { console.log(v) }} | |
const observable = createObservable(emitValue); | |
const unsubscribe = observable.subscribe(observer) | |
setTimeout(() => { | |
unsubscribe() | |
}, 4500) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
really concrete example, thanks