Skip to content

Instantly share code, notes, and snippets.

@ArtemRomanovsky
Last active March 26, 2022 11:56
Show Gist options
  • Save ArtemRomanovsky/3a9c10a647e3058307f568cbf6121479 to your computer and use it in GitHub Desktop.
Save ArtemRomanovsky/3a9c10a647e3058307f568cbf6121479 to your computer and use it in GitHub Desktop.
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)
@oneEyedSunday
Copy link

really concrete example, thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment