Skip to content
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 addTeardown(). Closes #3. Closes #19. #61

Merged
merged 4 commits into from
Sep 13, 2023
Merged

Add addTeardown(). Closes #3. Closes #19. #61

merged 4 commits into from
Sep 13, 2023

Conversation

domfarolino
Copy link
Collaborator

This PR clarifies the addTeardown() API, which is just syntactic sugar over responding accordingly to Subscriber#signal. I'm honestly not 100% sure if we need it, but it does seem like a nice first-class convenience API to get around the pesky is-this-signal-already-aborted check that would have to be made by ever subscriber with a clean-up function, at least until AbortSignal gets an API like whenAborted().

My only concern here is that it might be confusing if we expose both Subscriber#signal and Subscriber#addTeardown(), when you really only need one or the other. If we're going to have this first-class API, I kind of lean towards not exposing Subscriber#signal anymore, and pushing people to use addTeardown() exclusively, but what do you think @benlesh?

@domfarolino domfarolino marked this pull request as ready for review September 12, 2023 15:45
domfarolino and others added 2 commits September 13, 2023 14:56
The intent with that analogy was to describe how *part* of `addTeardown()`
is syntactic sugar over immediately checking `subscriber.signal.aborted`,
and *otherwise* setting the given cleanup function to the signal's abort
handler, and also invoking it during `complete()` and `error()`, but that
latter part was not clear at all and was contradictory as @annevk pointed
out. So this commit removes the example, in favor of the earlier descriptive
text.
@benlesh benlesh merged commit 8b9c989 into master Sep 13, 2023
@benlesh benlesh deleted the teardown branch September 13, 2023 13:52
@@ -470,6 +470,7 @@ If the subscriber has already been aborted (i.e., `subscriber.signal.aborted` is
- From `complete()`, after the subscriber's complete handler (if any) is
invoked
- From `error()`, after the subscriber's error handler (if any) is invoked
- The signal passed to the subscription is aborted by the user.
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Technically I don't think this was needed because of https://github.com/domfarolino/observable/pull/61/files#diff-b335630551682c19a781afebcf4d07bf978fb1f8ac04c6bf87428ed5106870f5R466-R467 (i.e., we're already in the "Otherwise" branch here) but I guess it can't hurt?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants