Skip to content

Instantly share code, notes, and snippets.

@drumnickydrum
Last active February 6, 2023 22:58
Show Gist options
  • Save drumnickydrum/b219cf4f3957bdfd1197e51d01f1f3aa to your computer and use it in GitHub Desktop.
Save drumnickydrum/b219cf4f3957bdfd1197e51d01f1f3aa to your computer and use it in GitHub Desktop.
[RxJS: Observable vs Promise] Observable vs. Promise Cheat Sheet #rxjs #observable #promise #angular

https://v12.angular.io/guide/comparing-observables#cheat-sheet

OPERATION OBSERVABLE PROMISE
Creation new Observable((observer) => { observer.next(123); }); new Promise((resolve, reject) => { resolve(123); });
Transform obs.pipe(map((value) => value * 2)); promise.then((value) => value * 2);
Subscribe sub = obs.subscribe((value) => { console.log(value) }); promise.then((value) => { console.log(value); });
Unsubscribe sub.unsubscribe(); Implied by promise resolution.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment