tc39 / proposal-observable

Observables for ECMAScript
https://tc39.github.io/proposal-observable/
3.08k stars 90 forks source link

Should we protect against reentrancy? #67

Open zenparsing opened 9 years ago

zenparsing commented 9 years ago

@jhusain @blesh

Should the wrapped observer protect against reentrancy? Currently it doesn't. In order to protect against reentrancy, we would need to maintain a state flag in the wrapped observer, and if the observer is currently running, then do one of the following:

benlesh commented 9 years ago

I believe we added logic for this to Subjects in RxJS 5, but not for Observers themselves. I don't think it's needed, but it doesn't hurt to look into it. /cc @trxcllnt

I guess a user could do something weird like:

let _observer;
new Observable(observer => {
  _observer = observer;
  observer.next('go!');
}).subscribe({
  next(x) {  _observer.next('wee'); }
});

I'm not sure why anyone would try to do that.

benlesh commented 9 years ago

... well... actually hold on.

There's the expand operator in RxJS that actually does this (sorta) by design. Values are both emitted and pumped back into the selector function by sending them back into the subscriber's (observer's) own next.

benlesh commented 9 years ago

... I suppose that's more of an implementation detail of the observer for that operator, and it wouldn't be too hard to develop around a reentrancy check.

trxcllnt commented 9 years ago

@blesh we protect against re-entrant error and complete calls, but not next, because doing it without throwing errors or dropping values necessitates introducing unbounded buffers.

benlesh commented 9 years ago

That's right, thank you for reminding me, @trxcllnt.

benjamingr commented 8 years ago

You can protect against immediate reentrency like @blesh 's example but not chains - that sounds like a reasonable compromise - no?

Also - what's so bad about reentrency in the first place?

benjamingr commented 8 years ago

Can we agree to not protect against reentrency?

benlesh commented 8 years ago

I don't think we should protect against next reentrancy... but, error and complete we probably should, since those are terminal events.

benjamingr commented 8 years ago

@blesh why? I'm wondering if we can/should just throw when trying to next an observable which is completed by default (and let subclasses take care of allowing it in odd cases).

niklas-wortmann commented 5 years ago

I think this could lead to several problems (more from an api users point of view and might be very subjective):

Additionally I don't see added value but added complexity by additional error handling?

ivan7237d commented 3 years ago

@Blesh we protect against re-entrant error and complete calls, but not next, because doing it without throwing errors or dropping values necessitates introducing unbounded buffers.

I'm really curious to find out more detail on why unbounded buffers are considered a deal breaker in this case.