Giter VIP home page Giter VIP logo

Comments (3)

benlesh avatar benlesh commented on May 26, 2024

It will be unfortunate if subscribe is async again. One of the issues I had with the two methods is then how should connect work on a ConnectableObservable (The result of a multicast)? I realize this proposal isn't RxJS, but a connectable observable or a "hot" observable seems like an inevitability. Would there need to be a connectSync and a connectAsync?

a subscribeOn is just a lot more flexible. FWIW, it seems like JavaScript should have native schedulers, because it's silly people keep reinventing microtask polyfills. That would be a whole different ball of wax, though.

from es-observable.

zenparsing avatar zenparsing commented on May 26, 2024

I think async subscription is not intuitive for the general case. If I say "subscribe", I expect to receive any event which happens from the time "subscribe" returns onward. That's the crux of the EventTarget problem. In my opinion, this problem is general in scope: the issue will arise whenever we want to model events which are not buffered.

The goal of avoiding zalgo is good, though, and we should take it seriously.

Having two methods solves one problem, but it creates another: how is the non-expert developer supposed to know which is appropriate? The difference is too subtle, and I would rather this thing "just work" without having to explain such subtleties.

The ideal, for me, is a universe where subscription is always sync, but observables never deliver data before "subscribe" has completed. That's why I have Observable.of delivering its arguments in a job rather than synchronously.

Unfortunately, I was unable to come up with an API which would elegantly enforce such a limitation. In the end, I was content with core API not enforcing any such restriction, and instead relying on best-practices to emerge among users (with the help of the good example set by Observable.of).

Javascript is definitely missing an enqueueJob primitive though.

At the end of the day, the zalgo problem might not even matter that much. If observables are ultimately compatible with async iteration statements, then users can "subscribe" to an observable like this:

for await (let x of someObservable) {
    // Do whatever with `x`
}

Since control flow doesn't get split into sync and async paths, there is no zalgo to worry about.

from es-observable.

zenparsing avatar zenparsing commented on May 26, 2024

Closing due to inactivity (and I'm still opposed to two subscription methods in the core proposal).

from es-observable.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.