2

Hello coming from c# i am struggling a bit to understand which is what when it comes to typescript.

So a Promise in Typescript would be the equivalent of a C# Task and while in C# i unwrap it using await in the latter i acess the data inside the context with subscribe ?

What is the relationship between Promise and Observable. So far i understood that Observable class behaves like the one in System.Reactive but where does Promise come in this equation?

Why do i have the toPromise extension method defined for an Observable? I am trying to do a parallel with C# and you can't convert an IEnumerable/IObservable to a Task.

How does that even make sense?I have a stream .Why would i await it?There might be no ending to that stream.I would understand if you await an element of the Observable but why on the whole?

Bercovici Adrian
  • 8,794
  • 17
  • 73
  • 152

1 Answers1

2

Promise and Observable are the same only with respect them both being tools for modeling async operations.

Their main difference is that Observable operates on stream of events, thus it has array-like operators while, on the other hand, Promise is an one time stop when it comes to async operations > once async operation finishes (or fails), your Promise is done and cannot be used anymore.

dee zg
  • 13,793
  • 10
  • 42
  • 82
  • So basically `Observable` is the same as in `C#` meaning that you can indeed `replay`,`map` ,`fold` , combine streams etc, `subscribe` ..etc ,derived from `IEnumerable` while `Promise` is a typical `Task` that can be run `sync` or `async` ,and the construct `then` is `ContinueWith` equivalent.Am i right? – Bercovici Adrian Nov 09 '18 at 13:35