Promise based Observable proposal

Isiah Meadows isiahmeadows at gmail.com
Tue May 10 00:11:52 UTC 2016


Probably best to first see how people react here:
https://github.com/zenparsing/es-observable

You also might appreciate the async generator/iterator proposal here:
https://github.com/tc39/proposal-async-iteration

(Note: observables push directly to iterators and are event based, while
async iterators are effectively iterators of promises, and they are
functionally equivalent, but they are two different ways of looking at the
same problem. Observables are better with single events, while async
iterators are like normal iterators. They are both heavily promise-based.)

On Mon, May 9, 2016, 03:48 Yad Smood <y.s.inside at gmail.com> wrote:

> Hi everyone,
>
> I've been working on implementing a Promise based Observable proposal.
>
> The main goal is to make the Observable composable, every subscribe will
> return a new Observable, and every listener will try to resolve the
> returned value as a Promise. Promise can't resolve multiple times, this
> class makes it possible, so that you can easily map, filter and even back
> pressure events in a promise way.
>
> For live example: Double Click Demo
> <https://jsbin.com/niwuti/edit?html,js,output>.
>
> The implementation is here:
> https://github.com/ysmood/yaku#observableexecutor
>
> Code example:
>
> ```js
> var Observable = require("yaku/lib/Observable");
> var linear = new Observable();
>
> var x = 0;
> setInterval(linear.next, 1000, x++);
>
> // Wait for 2 sec then emit the next value.
> var quad = linear.subscribe(async x => {
>     await sleep(2000);
>     return x * x;
> });
>
> var another = linear.subscribe(x => -x);
>
> quad.subscribe(
>     value => { console.log(value); },
>     reason => { console.error(reason); }
> );
>
> // Emit error
> linear.error(new Error("reason"));
>
> // Unsubscribe an observable.
> quad.unsubscribe();
>
> // Unsubscribe all subscribers.
> linear.subscribers = [];
> ```
>
> The lib itself is on a very early stage, please leave a comment if you
> have any idea on it.
> _______________________________________________
> es-discuss mailing list
> es-discuss at mozilla.org
> https://mail.mozilla.org/listinfo/es-discuss
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20160510/de1f594b/attachment.html>


More information about the es-discuss mailing list