Coder Social home page Coder Social logo

Comments (6)

benjamingr avatar benjamingr commented on September 13, 2024

Nice to e-see you here!

Quoting some of my comments from earlier about sync subscription:

An important thing to realize is that the overhead for an async function call is the same if you have 10000 calls or 1 call since it groups all the calls and executes them synchronously after a single timer.

In addition, implementations can detect that the subscriber fired the event asynchronously (since they know before and after the observer function ran) (that is - post subscribe) and avoid the async overhead altogether and execute it synchronously (while still keeping async semantics).

Also +1 for "I don't think performance arguments without data hold any value"

And later:

Of course, the thing is like @domenic said is that the penalty for scheduling a function asynchronously happens once and can be avoided in practice in most cases. For example, in a chain of mapd observers you only need to perform the async deferral once - and even that's only true if you're only just setting the handlers up once you know you're in a future turn than the one you installed the handlers in you can invoke them synchronously.

This is a very simple optimization that some promise libraries do - basically you get async subscription semantics visibly but in practice your'e doing sync function dispatch most of the time.

I'm also with @zenpraing in that I'm not sure I understand your sync use case but would like to learn more about it ::)

from proposal-observable.

benjamingr avatar benjamingr commented on September 13, 2024

The connect would allow for the subscription consumer to signal to the observable it is ready to receive values (synchronously or otherwise). Calls to connect after subscription or unsubscription have taken place would have no effect.

This would cause Zalgo, we might as well make it synchronous. Namely it is possible in this scheme to observe whether or not the a subscription happened before or after a value was received.

from proposal-observable.

tgriesser avatar tgriesser commented on September 13, 2024

Nice to e-see you here!

You as well!

Also +1 for "I don't think performance arguments without data hold any value"

Yep, this is not as much of a performance argument as a more inclusive general use cases argument.

we might as well make it synchronous.

Well, not exactly, if it were fully synchronous you couldn't do this:

var subscription = observable.subscribe(generator)
subscription.unsubscribe()

And be guaranteed that the unsubscribe could be called before the first value is sent. Unless I misunderstand what you mean there

This would cause Zalgo

As I understand it Zalgo matters for promises because they're an object which is passed around/chained, so the async guarantees of the promise matter far beyond the initial call site.

Unlike promises, the effects of Observables are more or less limited to the containing scope(s), so it seems it'd be appropriate the consumer be able to shortcut the async guarantee as they are aware of the behavior of the observable, basically inverting the control of the guarantee of subscription execution a bit.

from proposal-observable.

benjamingr avatar benjamingr commented on September 13, 2024

Unlike promises, the effects of Observables are more or less limited to the containing scope(s), so it seems it'd be appropriate the consumer be able to shortcut the async guarantee as they are aware of the behavior of the observable, basically inverting the control of the guarantee of subscription execution a bit.

That has not been my experience with observables - in libraries like RxJS (which I often use with React) observables are passed all around, chained, and moved between scopes.

Being able to shortcut a guarantee - especially if the guarantee is not the obvious default doesn't sound like much of a guarantee at all. With a symbol it at least looks private :)

from proposal-observable.

tgriesser avatar tgriesser commented on September 13, 2024

That has not been my experience with observables - in libraries like RxJS (which I often use with React) observables are passed all around, chained, and moved between scopes.

Sure, probably the case for the higher order functions wrapping the observable primitive, but FWIW the RxJS Observable does not make any guarantees of asynchrony in the subscription.

Also, potentially relevant: ReactiveX/rxjs#12 (comment)

Anyway, yeah maybe the Symbol works as long as it's sticking around, just wanted to throw out another idea for this and see what anyone thought.

from proposal-observable.

tgriesser avatar tgriesser commented on September 13, 2024

Closing in favor of discussion on #38

from proposal-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.