kefirjs / kefir

A Reactive Programming library for JavaScript
https://kefirjs.github.io/kefir/
MIT License
1.87k stars 97 forks source link

Request: .toPromise() #95

Closed Macil closed 9 years ago

Macil commented 9 years ago

A .toPromise([PromiseCtr]) method on observables is something I find myself reaching for often and would be a sensible corollary to Kefir.fromPromise(promise).

I figure it should be consistent with the Bacon method. Optional parameter to specify the promise constructor (or else the global Promise is used), and it resolves with the last event from the stream. (I would have gone with resolving with the first, but both Bacon and RxJS do it on the last and I know if Kefir does it the other way then I'll get it wrong in all of them forever.) (Note that at the current time the Bacon API doc page has an incorrect description about toPromise. (fixed) The Bacon readme is accurate.) If the stream ends before emitting a value or error, then the promise never resolves.

rpominov commented 9 years ago

I was going to add this eventually, thanks for the reminder :) Currently work on the transition to ES6, will probably do this after it done.

rpominov commented 9 years ago

Not sure where it should be in the docs. Probably in the section with subscription methods (.on/.of) as it also related to consuming events / taking events outside of Kefir.

We should also rename this section from "Main observable methods" to something like "Subscribe / add side effects". This should be done long ago, "Main observable methods" is an awful title. But problem is with "Subscribe / add side effects" it also confusing why .toProperty is in there.

Any ideas?

rpominov commented 9 years ago

Done in 2.3.0 http://pozadi.github.io/kefir/#to-promise