Promises vs Observables example

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments

Just in general for me I dislike YouTube tutorials vs just a webpage with text and picture examples. I don't know about other people but I figure out might be worth mentioning to little looking to get more views

👍︎︎ 5 👤︎︎ u/beardedheathen 📅︎︎ Oct 22 2019 🗫︎ replies
Captions
to demonstrate the difference between promises and observables I'll create this promise that returns a value of dog after 100 milliseconds and then I'll execute this promise by calling that then and simply logging the result into console and here we see our dog now using the same approach let's create an observable where I will copy this existing settimeout function and replace this resolved with observer dot next and again I'll execute this observable by calling dot subscribe and put the value into console and here it is now to demonstrate the first main difference between observables and promises I'm going to duplicate this dot next goal and along with dog returned cat and bird and we see it in the console now let me try to do the same thing in the existing promise and it just doesn't work you can't do that with promises so the first difference is that observables can return multiple values another cool thing about observables is that they behave like arrays so here I can call dot filter and filter out any other values that are not a bird and here we get just the bird in the console and one more thing with observables I can save a reference to the subscription just like that and then call unsubscribe to cancel it which cancels the observable you can't do that with promises
Info
Channel: Irek Mirgaleev
Views: 24,174
Rating: 4.9836736 out of 5
Keywords: promise, observable, javascript
Id: 3rbikUwGf9Y
Channel Id: undefined
Length: 1min 56sec (116 seconds)
Published: Thu Oct 10 2019
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.