-
Notifications
You must be signed in to change notification settings - Fork 16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Subscriber#active
boolean (take 2)
#82
Conversation
I'd love to hear from some others in the community about consideration of this API! If anyone, like perhaps @tbondwilkinson, @domenic, or @bakkot has any opinions I'd love to hear them, since I'm personally a little bit torn between the nice semantics that this API introduces, but I'm not sure how to weigh it against the actual user need / confusion of having two similar ways of gleaning the same information. |
I do view the concept of an Imagine a So I do think it's probably worth adding? I would expect people would almost universally pick checking |
I think that makes a lot of sense, thanks. I agree with the Promise analogy. I think I'm happy enough to land this now that we've gotten at least a little feedback, but if others feel strongly I'm open to hearing more discussion! |
This CL introduces an API, namely `subscriber.active` for determining the activity of an existing subscription. The `active` attribute gets set to false by the platform synchronously before the Observer's completion and error handlers are invoked. This has the effect of being observably `false` _within_ those handlers, unlike `subscriber.signal.aborted`. Please see the lengthy design notes in both WICG/observable#76 and WICG/observable#82. [email protected] For WPTs: Co-authored-by: [email protected] Bug: 1485981 Change-Id: I4604a80347ff30ff7be44a131bfdd3999b71252a
This CL introduces an API, namely `subscriber.active` for determining the activity of an existing subscription. The `active` attribute gets set to false by the platform synchronously before the Observer's completion and error handlers are invoked. This has the effect of being observably `false` _within_ those handlers, unlike `subscriber.signal.aborted`. Please see the lengthy design notes in both WICG/observable#76 and WICG/observable#82. [email protected] For WPTs: Co-authored-by: [email protected] Bug: 1485981 Change-Id: I4604a80347ff30ff7be44a131bfdd3999b71252a
This CL introduces an API, namely `subscriber.active` for determining the activity of an existing subscription. The `active` attribute gets set to false by the platform synchronously before the Observer's completion and error handlers are invoked. This has the effect of being observably `false` _within_ those handlers, unlike `subscriber.signal.aborted`. Please see the lengthy design notes in both WICG/observable#76 and WICG/observable#82. [email protected] For WPTs: Co-authored-by: [email protected] Bug: 1485981 Change-Id: I4604a80347ff30ff7be44a131bfdd3999b71252a
This CL introduces an API, namely `subscriber.active` for determining the activity of an existing subscription. The `active` attribute gets set to false by the platform synchronously before the Observer's completion and error handlers are invoked. This has the effect of being observably `false` _within_ those handlers, unlike `subscriber.signal.aborted`. Please see the lengthy design notes in both WICG/observable#76 and WICG/observable#82. [email protected] For WPTs: Co-authored-by: [email protected] Bug: 1485981 Change-Id: I4604a80347ff30ff7be44a131bfdd3999b71252a Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5017505 Commit-Queue: Dominic Farolino <[email protected]> Reviewed-by: Mason Freed <[email protected]> Cr-Commit-Position: refs/heads/main@{#1224384}
This closes #76. This PR introduces the
subscriber.active
boolean attribute that can be used from within an Observable to determine whether a subscription is still active. I am still personally a tiny but unsure whether this is really necessary, so I'd like to use this space to describe the semantics and how it differs from other APIs, so we can come to a conclusion on this, since @benlesh feels much more strongly about this API.On the surface it seems that
subscriber.active === !subscriber.signal.aborted
1, however this is not quite true. The lifecycle of an Observable is the following:subscriber.complete()/error()
is called from scriptObserver
dictionary for that matter.Observer#complete()/error()
body is runSubscriber#signal
is aborted (via an internalAbortController
)subscriber.signal.aborted
is truesubscriber.addTeardown()
) will run, as part of the abort algorithms associated withsubscriber.signal
The
subscriber.active
attribute intends to expose precisely when a subscription no longer becomes active (just before theObserver#complete()/error()
body is run), which is before thesubscriber.signal
is finally aborted. The only observable consequence I can think of for this is inside thecomplete()
/error()
methods, wheresubscriber.active
is already false butsubscriber.signal.aborted
is not yet true (since teardowns haven't run yet).I think that
subscriber.active
is a more sensible and ergonomic way to express the concept of an "inactive subscription", however I only hesitate to add it because I don't love the idea of having two different ways of getting this information with slightly different semantics. I'm curious if anyone would rely onsubscriber.active
in a way that!subscriber.signal.aborted
couldn't be used for (thus causing broken code).Here's an I can think of where
subscriber.signal.aborted
is insufficient for stopping an infinite loop:How important is it to protect against this kind of (highly contrived!) scenario? Or are there way less contrived scenarios where
subscriber.signal.aborted
is a footgun, and wheresubscriber.active
would be critical.Footnotes
Remember of course that
subscriber.signal
is aborted absolutely whenever a subscription is ended, not just when the subscriber unsubscribes / aborts thesignal
that it passed intosubscribe()
. ↩